|
| 1 | +component extends="org.lucee.cfml.test.LuceeTestCase" labels="data-provider-integration" skip=true { |
| 2 | + |
| 3 | + function beforeAll(){ |
| 4 | + variables.dir = getDirectoryFromPath(getCurrentTemplatePath()); |
| 5 | + |
| 6 | + // Fetch production extension list |
| 7 | + cfhttp( url="https://extension.lucee.org/rest/extension/provider/info/?withLogo=false", result="local.prod" ); |
| 8 | + |
| 9 | + if ( prod.status_code != 200 ) { |
| 10 | + throw "Failed to fetch production data: " & prod.status_code; |
| 11 | + } |
| 12 | + |
| 13 | + var response = deserializeJson( prod.fileContent ); |
| 14 | + |
| 15 | + // Handle response - struct with EXTENSIONS key containing query data |
| 16 | + if ( structKeyExists( response, "EXTENSIONS" ) ) { |
| 17 | + var extensions = response.EXTENSIONS; |
| 18 | + var cols = extensions.COLUMNS; |
| 19 | + var data = extensions.DATA; |
| 20 | + |
| 21 | + // Convert to array of structs |
| 22 | + variables.prodData = []; |
| 23 | + for ( var rowData in data ) { |
| 24 | + var row = {}; |
| 25 | + for ( var i = 1; i <= arrayLen( cols ); i++ ) { |
| 26 | + row[ cols[ i ] ] = rowData[ i ]; |
| 27 | + } |
| 28 | + arrayAppend( variables.prodData, row ); |
| 29 | + } |
| 30 | + } else { |
| 31 | + systemOutput( response, true); |
| 32 | + throw "Unexpected production response structure"; |
| 33 | + } |
| 34 | + |
| 35 | + systemOutput( "Fetched #arrayLen( variables.prodData )# extensions from production", true ); |
| 36 | + |
| 37 | + // Get unique extension IDs and collect all versions |
| 38 | + variables.extensionIDs = {}; |
| 39 | + for ( var ext in variables.prodData ) { |
| 40 | + if ( !structKeyExists( variables.extensionIDs, ext.id ) ) { |
| 41 | + variables.extensionIDs[ ext.id ] = { |
| 42 | + name: ext.name ?: "", |
| 43 | + versions: [] |
| 44 | + }; |
| 45 | + } |
| 46 | + |
| 47 | + // Add current version |
| 48 | + arrayAppend( variables.extensionIDs[ ext.id ].versions, ext.version ); |
| 49 | + |
| 50 | + // Add older versions if they exist |
| 51 | + if ( structKeyExists( ext, "older" ) && isArray( ext.older ) ) { |
| 52 | + for ( var olderVer in ext.older ) { |
| 53 | + arrayAppend( variables.extensionIDs[ ext.id ].versions, olderVer ); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + systemOutput( "Found #structCount( variables.extensionIDs )# unique extension IDs", true ); |
| 59 | + |
| 60 | + // Test core version that triggers the bug |
| 61 | + variables.testCoreVersion = "6.2.4.24"; |
| 62 | + } |
| 63 | + |
| 64 | + function run( testResults , testBox ) { |
| 65 | + |
| 66 | + describe( "validate production extension API returns correct versions", function() { |
| 67 | + |
| 68 | + it (title="test production has extensions", body=function(){ |
| 69 | + expect( structCount( variables.extensionIDs ) ).toBeGT( 0 ); |
| 70 | + }); |
| 71 | + |
| 72 | + it (title="test each extension returns correct version for coreVersion 6.2.4.24", body=function(){ |
| 73 | + var failed = []; |
| 74 | + var tested = 0; |
| 75 | + var skipped = 0; |
| 76 | + |
| 77 | + for ( var extID in variables.extensionIDs ) { |
| 78 | + var extInfo = variables.extensionIDs[ extID ]; |
| 79 | + |
| 80 | + // Call production API for this extension (redirect=false to get headers) |
| 81 | + cfhttp( |
| 82 | + url="https://extension.lucee.org/rest/extension/provider/full/#extID#?coreVersion=#variables.testCoreVersion#", |
| 83 | + result="local.response", |
| 84 | + redirect=false, |
| 85 | + timeout=10 |
| 86 | + ); |
| 87 | + |
| 88 | + if ( response.status_code == 404 ) { |
| 89 | + skipped++; |
| 90 | + continue; |
| 91 | + } |
| 92 | + |
| 93 | + if ( response.status_code != 302 ) { |
| 94 | + arrayAppend( failed, "#extInfo.name# (#extID#): Expected 302 redirect, got #response.status_code#" ); |
| 95 | + continue; |
| 96 | + } |
| 97 | + |
| 98 | + // Get Location header |
| 99 | + var location = ""; |
| 100 | + if ( structKeyExists( response.responseHeader, "Location" ) ) { |
| 101 | + location = response.responseHeader.Location; |
| 102 | + } |
| 103 | + |
| 104 | + if ( !len( location ) ) { |
| 105 | + arrayAppend( failed, "#extInfo.name# (#extID#): No Location header in redirect" ); |
| 106 | + continue; |
| 107 | + } |
| 108 | + |
| 109 | + // Extract filename from location (last part of URL) |
| 110 | + var filename = listLast( location, "/" ); |
| 111 | + |
| 112 | + // Extract version from filename using regex |
| 113 | + var versionMatch = reMatch( "(\d+\.)(\d+\.){1,2}\d+[^.]*", filename ); |
| 114 | + if ( arrayLen( versionMatch ) > 0 ) { |
| 115 | + var redirectVersion = versionMatch[ 1 ]; |
| 116 | + |
| 117 | + // Extract major version number |
| 118 | + var redirectMajor = val( listFirst( redirectVersion, "." ) ); |
| 119 | + |
| 120 | + // Check if redirect has old major version (< 10) and newer versions (>= 10) exist |
| 121 | + if ( redirectMajor < 10 ) { |
| 122 | + var hasNewer = false; |
| 123 | + for ( var v in extInfo.versions ) { |
| 124 | + var vMajor = val( listFirst( v, "." ) ); |
| 125 | + if ( vMajor >= 10 ) { |
| 126 | + hasNewer = true; |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + if ( hasNewer ) { |
| 132 | + arrayAppend( failed, "#extInfo.name# (#extID#): redirects to #redirectVersion# but has versions >= 10.x available" ); |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + tested++; |
| 138 | + } |
| 139 | + |
| 140 | + systemOutput( "Tested: #tested#, Skipped: #skipped#, Failed: #arrayLen( failed )#", true ); |
| 141 | + |
| 142 | + if ( arrayLen( failed ) > 0 ) { |
| 143 | + systemOutput( "Failures:", true ); |
| 144 | + for ( var f in failed ) { |
| 145 | + systemOutput( " - #f#", true ); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + expect( arrayLen( failed ) ).toBe( 0, "All extensions should return correct version" ); |
| 150 | + }); |
| 151 | + |
| 152 | + }); |
| 153 | + } |
| 154 | + |
| 155 | +} |
0 commit comments