Skip to content

Commit cf4ef44

Browse files
committed
LDEV-6067 add admin updates notification test
1 parent b63d75a commit cf4ef44

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

core/src/main/cfml/context/admin/update.cfm

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
1515
*
1616
---><cfsetting showdebugoutput="false">
17+
<cfparam name="url.json" default="false" type="boolean">
1718
<cftry>
1819
<cfparam name="session.alwaysNew" default="true" type="boolean">
1920
<cfinclude template="services.update.functions.cfm">
@@ -109,20 +110,24 @@
109110
<cfset request.adminType=url.adminType>
110111
<cfset external=getAllExternalData()>
111112

113+
<cfset extUpdates = []>
112114
<cfsavecontent variable="ext" trim="true">
113115
<cfloop query="extensions">
114116
<cfscript>
115117
sct = {};
116118
loop list="#extensions.columnlist()#" item="key" {
117119
sct[ key ]=extensions[ key ];
118120
}
119-
updateVersion= updateAvailable( sct, external );
120-
if (updateVersion eq "false")
121+
updateVersion = updateAvailable( sct, external );
122+
if ( updateVersion eq "false" )
121123
continue;
122-
uid=extensions.id
123-
link="";
124-
dn="";
125-
link="?action=ext.applications&action2=detail&id=#uid#";
124+
uid = extensions.id;
125+
link = "?action=ext.applications&action2=detail&id=#uid#";
126+
arrayAppend( extUpdates, {
127+
"name": extensions.name,
128+
"current": sct.version,
129+
"available": updateVersion
130+
} );
126131
</cfscript>
127132
<cfoutput>
128133
<a href="#link#" style="color:red;text-decoration:none;">- #extensions.name# - <b>#updateVersion#</b> ( #sct.version# ) </a><br>
@@ -209,6 +214,19 @@
209214
<cfset content=session[id].content>
210215
</cfif>
211216

217+
<cfif url.json>
218+
<cfset result = {
219+
"currentVersion": server.lucee.version,
220+
"hasUpdate": adminType == "server" && ( hasUpdate ?: false ),
221+
"availableVersion": available ?: "",
222+
"extensionUpdates": extUpdates ?: []
223+
}>
224+
<cfsetting showdebugoutput="false">
225+
<cfcontent reset="yes" type="application/json">
226+
<cfoutput>#serializeJson( result )#</cfoutput>
227+
<cfabort>
228+
</cfif>
229+
212230
<cfoutput>#content#</cfoutput>
213231

214232
<cfcatch>

loader/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project default="core" basedir="." name="Lucee"
33
xmlns:resolver="antlib:org.apache.maven.resolver.ant">
44

5-
<property name="version" value="6.2.5.22-SNAPSHOT"/>
5+
<property name="version" value="6.2.5.23-SNAPSHOT"/>
66

77
<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
88
<classpath>

loader/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.lucee</groupId>
55
<artifactId>lucee</artifactId>
6-
<version>6.2.5.22-SNAPSHOT</version>
6+
<version>6.2.5.23-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<name>Lucee Loader Build</name>

test/general/AdminPages.cfc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,24 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
114114
// 500 (mappng doesn't exist)
115115
checkUrl( adminRoot, "index.cfm?action=resources.mappings&action2=create&virtual=/lucee/adminMissing", 500 );
116116
});
117+
118+
it( title="check admin updates notification (JSON)", body=function(){
119+
local.content = checkUrl( adminRoot, "update.cfm?adminType=server&json=true", 200 );
120+
expect( isJson( local.content ) ).toBeTrue( "Response should be JSON" );
121+
local.data = deserializeJson( local.content );
122+
local.TAB = chr( 9 );
123+
if ( local.data.hasUpdate || arrayLen( local.data.extensionUpdates ) ) {
124+
systemOutput( "", true );
125+
systemOutput( "Admin reports update(s) available:", true );
126+
if ( local.data.hasUpdate ) {
127+
systemOutput( TAB & "Core: " & local.data.currentVersion & " -> " & local.data.availableVersion, true );
128+
}
129+
for ( local.ext in local.data.extensionUpdates ) {
130+
systemOutput( TAB & "Extension: " & local.ext.name & " " & local.ext.current & " -> " & local.ext.available, true );
131+
}
132+
systemOutput( "", true );
133+
}
134+
});
117135
});
118136
}
119137

@@ -147,7 +165,8 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
147165
//expect( local.result.status ).toBeBetween( 200, 399, adminRoot & page & " returned status code: " & local.result.status);
148166
// if ( local.result.status neq arguments.statusCode )
149167
// systemOutput( trim(local.result.filecontent), true );
150-
expect( local.result.status ).toBe( arguments.statusCode,
168+
expect( local.result.status ).toBe( arguments.statusCode,
151169
arguments.adminRoot & page & " returned status code: " & local.result.status );
170+
return local.result.fileContent;
152171
}
153172
}

0 commit comments

Comments
 (0)