|
| 1 | +component extends="org.lucee.cfml.test.LuceeTestCase" labels="archive,mapping" { |
| 2 | + |
| 3 | + variables.adminPassword = ""; |
| 4 | + variables.testDir = ""; |
| 5 | + variables.srcBase = ""; |
| 6 | + |
| 7 | + function beforeAll() { |
| 8 | + variables.adminPassword = request.WEBADMINPASSWORD; |
| 9 | + variables.testDir = getTempDirectory() & "archivesTest/"; |
| 10 | + variables.srcBase = getTempDirectory() & "archivesSrc/"; |
| 11 | + |
| 12 | + // cleanup from previous runs |
| 13 | + if ( directoryExists( variables.testDir ) ) directoryDelete( variables.testDir, true ); |
| 14 | + if ( directoryExists( variables.srcBase ) ) directoryDelete( variables.srcBase, true ); |
| 15 | + directoryCreate( variables.testDir, true, true ); |
| 16 | + directoryCreate( variables.srcBase, true, true ); |
| 17 | + |
| 18 | + // build all the .lar archives we need |
| 19 | + _buildMappingArchive(); |
| 20 | + _buildComponentArchive(); |
| 21 | + _buildCustomTagArchive(); |
| 22 | + _buildHybridPhysical(); |
| 23 | + _buildHybridPhysicalFirst(); |
| 24 | + _buildMissingPhysical(); |
| 25 | + _buildMissingArchive(); |
| 26 | + } |
| 27 | + |
| 28 | + function afterAll() { |
| 29 | + // remove admin mappings used during archive creation |
| 30 | + var virtuals = [ "/archivesTest-mapping", "/archivesTest-component", "/archivesTest-customtag", "/archivesTest-hybrid", "/archivesTest-hybridPF" ]; |
| 31 | + for ( var v in virtuals ) { |
| 32 | + try { admin action="removeMapping" type="web" password="#variables.adminPassword#" virtual="#v#"; } catch ( any e ) {} |
| 33 | + } |
| 34 | + try { admin action="removeComponentMapping" type="web" password="#variables.adminPassword#" virtual="/archivesTest-component"; } catch ( any e ) {} |
| 35 | + try { admin action="removeCustomTag" type="web" password="#variables.adminPassword#" virtual="/archivesTest-customtag"; } catch ( any e ) {} |
| 36 | + } |
| 37 | + |
| 38 | + function run( testResults, testBox ) { |
| 39 | + |
| 40 | + describe( "Application.cfc this.mappings with archive", function() { |
| 41 | + |
| 42 | + it( "should resolve a template from a LAR via this.mappings", function() { |
| 43 | + var result = _internalRequest( |
| 44 | + template: "#_uri()#/mapping/index.cfm" |
| 45 | + ); |
| 46 | + expect( result.fileContent.trim() ).toBe( "hello-from-archive" ); |
| 47 | + }); |
| 48 | + |
| 49 | + }); |
| 50 | + |
| 51 | + describe( "Application.cfc this.componentPaths with archive", function() { |
| 52 | + |
| 53 | + it( "should instantiate a CFC from a LAR via this.componentPaths", function() { |
| 54 | + var result = _internalRequest( |
| 55 | + template: "#_uri()#/componentPaths/index.cfm" |
| 56 | + ); |
| 57 | + expect( result.fileContent.trim() ).toBe( "component-from-archive" ); |
| 58 | + }); |
| 59 | + |
| 60 | + }); |
| 61 | + |
| 62 | + describe( "Application.cfc this.customTagPaths with archive", function() { |
| 63 | + |
| 64 | + it( title="should invoke a custom tag from a LAR via this.customTagPaths", skip=true, body=function() { |
| 65 | + // LDEV-6173: custom tag resolution does not consult archive |
| 66 | + var result = _internalRequest( |
| 67 | + template: "#_uri()#/customTagPaths/index.cfm" |
| 68 | + ); |
| 69 | + expect( result.fileContent.trim() ).toBe( "customtag-from-archive" ); |
| 70 | + }); |
| 71 | + |
| 72 | + }); |
| 73 | + |
| 74 | + describe( "Hybrid physical + archive with primary=archive", function() { |
| 75 | + |
| 76 | + it( title="should prefer archive over physical when primary is archive", skip=true, body=function() { |
| 77 | + // LDEV-6172: initPhysical() overrides physicalFirst before archive init |
| 78 | + var result = _internalRequest( |
| 79 | + template: "#_uri()#/hybrid/index.cfm", |
| 80 | + urls: { scene: "archive" } |
| 81 | + ); |
| 82 | + expect( result.fileContent.trim() ).toBe( "from-archive" ); |
| 83 | + }); |
| 84 | + |
| 85 | + it( "should fall back to physical for files not in the archive", function() { |
| 86 | + var result = _internalRequest( |
| 87 | + template: "#_uri()#/hybrid/index.cfm", |
| 88 | + urls: { scene: "fallback" } |
| 89 | + ); |
| 90 | + expect( result.fileContent.trim() ).toBe( "from-physical" ); |
| 91 | + }); |
| 92 | + |
| 93 | + }); |
| 94 | + |
| 95 | + describe( "Hybrid physical + archive with primary=physical (default)", function() { |
| 96 | + |
| 97 | + it( "should prefer physical over archive when primary is physical", function() { |
| 98 | + var result = _internalRequest( |
| 99 | + template: "#_uri()#/hybridPhysicalFirst/index.cfm", |
| 100 | + urls: { scene: "physical" } |
| 101 | + ); |
| 102 | + expect( result.fileContent.trim() ).toBe( "from-physical" ); |
| 103 | + }); |
| 104 | + |
| 105 | + it( "should fall back to archive for files not on disk", function() { |
| 106 | + var result = _internalRequest( |
| 107 | + template: "#_uri()#/hybridPhysicalFirst/index.cfm", |
| 108 | + urls: { scene: "fallback" } |
| 109 | + ); |
| 110 | + expect( result.fileContent.trim() ).toBe( "from-archive" ); |
| 111 | + }); |
| 112 | + |
| 113 | + }); |
| 114 | + |
| 115 | + describe( "Graceful fallback when one side of mapping is missing", function() { |
| 116 | + |
| 117 | + it( "should fall back to physical when archive path does not exist", function() { |
| 118 | + var result = _internalRequest( |
| 119 | + template: "#_uri()#/missingArchive/index.cfm" |
| 120 | + ); |
| 121 | + expect( result.fileContent.trim() ).toBe( "from-physical" ); |
| 122 | + }); |
| 123 | + |
| 124 | + it( "should fall back to archive when physical path does not exist", function() { |
| 125 | + var result = _internalRequest( |
| 126 | + template: "#_uri()#/missingPhysical/index.cfm" |
| 127 | + ); |
| 128 | + expect( result.fileContent.trim() ).toBe( "hello-from-archive" ); |
| 129 | + }); |
| 130 | + |
| 131 | + }); |
| 132 | + |
| 133 | + } |
| 134 | + |
| 135 | + // ---- archive builders ---- |
| 136 | + |
| 137 | + private function _buildMappingArchive() { |
| 138 | + var srcDir = variables.srcBase & "mapping/"; |
| 139 | + var larFile = variables.testDir & "mapping.lar"; |
| 140 | + var virtual = "/archivesTest-mapping"; |
| 141 | + |
| 142 | + directoryCreate( srcDir, true, true ); |
| 143 | + fileWrite( srcDir & "hello.cfm", "<cfset writeOutput( 'hello-from-archive' )>" ); |
| 144 | + |
| 145 | + admin action="updateMapping" type="web" password="#variables.adminPassword#" |
| 146 | + virtual="#virtual#" physical="#srcDir#" archive="" primary="physical" |
| 147 | + toplevel="true" trusted="no"; |
| 148 | + |
| 149 | + admin action="createArchive" type="web" password="#variables.adminPassword#" |
| 150 | + file="#larFile#" virtual="#virtual#" addCFMLFiles="false" addNonCFMLFiles="false"; |
| 151 | + |
| 152 | + // nuke the source so we know it comes from the archive |
| 153 | + directoryDelete( srcDir, true ); |
| 154 | + } |
| 155 | + |
| 156 | + private function _buildComponentArchive() { |
| 157 | + var srcDir = variables.srcBase & "components/"; |
| 158 | + var larFile = variables.testDir & "components.lar"; |
| 159 | + var virtual = "/archivesTest-component"; |
| 160 | + |
| 161 | + directoryCreate( srcDir, true, true ); |
| 162 | + fileWrite( srcDir & "ArchiveGreeter.cfc", 'component { function greet() { return "component-from-archive"; } }' ); |
| 163 | + |
| 164 | + admin action="updateComponentMapping" type="web" password="#variables.adminPassword#" |
| 165 | + virtual="#virtual#" physical="#srcDir#" archive="" primary="physical"; |
| 166 | + |
| 167 | + admin action="createComponentArchive" type="web" password="#variables.adminPassword#" |
| 168 | + file="#larFile#" virtual="#virtual#" addCFMLFiles="false" addNonCFMLFiles="false"; |
| 169 | + |
| 170 | + directoryDelete( srcDir, true ); |
| 171 | + } |
| 172 | + |
| 173 | + private function _buildCustomTagArchive() { |
| 174 | + var srcDir = variables.srcBase & "customtags/"; |
| 175 | + var larFile = variables.testDir & "customtags.lar"; |
| 176 | + var virtual = "/archivesTest-customtag"; |
| 177 | + |
| 178 | + directoryCreate( srcDir, true, true ); |
| 179 | + fileWrite( srcDir & "cf_greeting.cfm", '<cfif thisTag.executionMode eq "start"><cfset caller.ctResult = "customtag-from-archive"></cfif>' ); |
| 180 | + |
| 181 | + admin action="updateCustomTag" type="web" password="#variables.adminPassword#" |
| 182 | + virtual="#virtual#" physical="#srcDir#" archive="" primary="physical"; |
| 183 | + |
| 184 | + admin action="createCTArchive" type="web" password="#variables.adminPassword#" |
| 185 | + file="#larFile#" virtual="#virtual#" addCFMLFiles="false" addNonCFMLFiles="false"; |
| 186 | + |
| 187 | + directoryDelete( srcDir, true ); |
| 188 | + } |
| 189 | + |
| 190 | + private function _buildHybridPhysical() { |
| 191 | + var hybridSrcDir = variables.srcBase & "hybrid/"; |
| 192 | + var hybridLarFile = variables.testDir & "hybrid.lar"; |
| 193 | + var virtual = "/archivesTest-hybrid"; |
| 194 | + var physDir = variables.testDir & "hybrid-physical/"; |
| 195 | + |
| 196 | + // build archive with hello.cfm that says "from-archive" |
| 197 | + directoryCreate( hybridSrcDir, true, true ); |
| 198 | + fileWrite( hybridSrcDir & "hello.cfm", "<cfset writeOutput( 'from-archive' )>" ); |
| 199 | + |
| 200 | + admin action="updateMapping" type="web" password="#variables.adminPassword#" |
| 201 | + virtual="#virtual#" physical="#hybridSrcDir#" archive="" primary="physical" |
| 202 | + toplevel="true" trusted="no"; |
| 203 | + |
| 204 | + admin action="createArchive" type="web" password="#variables.adminPassword#" |
| 205 | + file="#hybridLarFile#" virtual="#virtual#" addCFMLFiles="false" addNonCFMLFiles="false"; |
| 206 | + |
| 207 | + directoryDelete( hybridSrcDir, true ); |
| 208 | + |
| 209 | + // create physical dir with a different hello.cfm (should be ignored) and a fallback.cfm (not in archive) |
| 210 | + directoryCreate( physDir, true, true ); |
| 211 | + fileWrite( physDir & "hello.cfm", "<cfset writeOutput( 'from-physical-should-not-see' )>" ); |
| 212 | + fileWrite( physDir & "fallback.cfm", "<cfset writeOutput( 'from-physical' )>" ); |
| 213 | + } |
| 214 | + |
| 215 | + private function _buildHybridPhysicalFirst() { |
| 216 | + var srcDir = variables.srcBase & "hybridPF/"; |
| 217 | + var larFile = variables.testDir & "hybridPF.lar"; |
| 218 | + var virtual = "/archivesTest-hybridPF"; |
| 219 | + var physDir = variables.testDir & "hybridPF-physical/"; |
| 220 | + |
| 221 | + // archive has hello.cfm (should lose to physical) and archiveOnly.cfm (fallback target) |
| 222 | + directoryCreate( srcDir, true, true ); |
| 223 | + fileWrite( srcDir & "hello.cfm", "<cfset writeOutput( 'from-archive-should-not-see' )>" ); |
| 224 | + fileWrite( srcDir & "archiveOnly.cfm", "<cfset writeOutput( 'from-archive' )>" ); |
| 225 | + |
| 226 | + admin action="updateMapping" type="web" password="#variables.adminPassword#" |
| 227 | + virtual="#virtual#" physical="#srcDir#" archive="" primary="physical" |
| 228 | + toplevel="true" trusted="no"; |
| 229 | + |
| 230 | + admin action="createArchive" type="web" password="#variables.adminPassword#" |
| 231 | + file="#larFile#" virtual="#virtual#" addCFMLFiles="false" addNonCFMLFiles="false"; |
| 232 | + |
| 233 | + directoryDelete( srcDir, true ); |
| 234 | + |
| 235 | + // physical has hello.cfm only — no archiveOnly.cfm |
| 236 | + directoryCreate( physDir, true, true ); |
| 237 | + fileWrite( physDir & "hello.cfm", "<cfset writeOutput( 'from-physical' )>" ); |
| 238 | + } |
| 239 | + |
| 240 | + private function _buildMissingPhysical() { |
| 241 | + // physical path points to a non-existent directory, archive is valid |
| 242 | + // reuse the mapping.lar which has hello.cfm |
| 243 | + var physDir = variables.testDir & "does-not-exist/"; |
| 244 | + // intentionally do NOT create physDir |
| 245 | + } |
| 246 | + |
| 247 | + private function _buildMissingArchive() { |
| 248 | + // archive path points to a non-existent .lar, physical is valid |
| 249 | + var physDir = variables.testDir & "missingArchive-physical/"; |
| 250 | + directoryCreate( physDir, true, true ); |
| 251 | + fileWrite( physDir & "hello.cfm", "<cfset writeOutput( 'from-physical' )>" ); |
| 252 | + } |
| 253 | + |
| 254 | + private string function _uri() { |
| 255 | + var baseURI = "/test/#listLast( getDirectoryFromPath( getCurrentTemplatePath() ), "\/" )#/"; |
| 256 | + return baseURI & "archives"; |
| 257 | + } |
| 258 | + |
| 259 | +} |
0 commit comments