|
| 1 | +component extends="org.lucee.cfml.test.LuceeTestCase" labels="mapping,archive" { |
| 2 | + |
| 3 | + variables.testVirtual = "/ldev6165-test"; |
| 4 | + variables.adminPassword = ""; |
| 5 | + |
| 6 | + function beforeAll() { |
| 7 | + variables.adminPassword = request.WEBADMINPASSWORD; |
| 8 | + variables.oldMappings = GetApplicationSettings().mappings; |
| 9 | + // cleanup mapping from previous runs |
| 10 | + try { |
| 11 | + admin action="removeMapping" type="web" password="#variables.adminPassword#" virtual="#variables.testVirtual#"; |
| 12 | + } catch ( any e ) {} |
| 13 | + } |
| 14 | + |
| 15 | + function afterAll() { |
| 16 | + application action="update" mappings=variables.oldMappings; |
| 17 | + try { |
| 18 | + admin action="removeMapping" type="web" password="#variables.adminPassword#" virtual="#variables.testVirtual#"; |
| 19 | + } catch ( any e ) {} |
| 20 | + } |
| 21 | + |
| 22 | + private function createLarArchive( required string srcDir, required string larFile, boolean addNonCFMLFiles=false ) { |
| 23 | + // create mapping pointing to physical source |
| 24 | + admin |
| 25 | + action="updateMapping" |
| 26 | + type="web" |
| 27 | + password="#variables.adminPassword#" |
| 28 | + virtual="#variables.testVirtual#" |
| 29 | + physical="#arguments.srcDir#" |
| 30 | + toplevel="true" |
| 31 | + archive="" |
| 32 | + primary="physical" |
| 33 | + trusted="no"; |
| 34 | + |
| 35 | + // create an archive (compiles CFML to .class files) |
| 36 | + admin |
| 37 | + action="createArchive" |
| 38 | + type="web" |
| 39 | + password="#variables.adminPassword#" |
| 40 | + file="#arguments.larFile#" |
| 41 | + virtual="#variables.testVirtual#" |
| 42 | + addCFMLFiles="false" |
| 43 | + addNonCFMLFiles="#arguments.addNonCFMLFiles#"; |
| 44 | + |
| 45 | + expect( fileExists( arguments.larFile ) ).toBeTrue( "LAR file should exist" ); |
| 46 | + |
| 47 | + // switch mapping to archive-only, no physical |
| 48 | + admin |
| 49 | + action="updateMapping" |
| 50 | + type="web" |
| 51 | + password="#variables.adminPassword#" |
| 52 | + virtual="#variables.testVirtual#" |
| 53 | + physical="" |
| 54 | + toplevel="true" |
| 55 | + archive="#arguments.larFile#" |
| 56 | + primary="archive" |
| 57 | + trusted="no"; |
| 58 | + |
| 59 | + // remove the physical source so we know it's coming from the archive |
| 60 | + directoryDelete( arguments.srcDir, true ); |
| 61 | + } |
| 62 | + |
| 63 | + function run( testResults, testBox ) { |
| 64 | + describe( "LDEV-6165: LAR archive mapping with only compiled CFML", function() { |
| 65 | + |
| 66 | + it( "should resolve pages from a CFML-only LAR archive", function() { |
| 67 | + var testDir = getTempDirectory() & "LDEV6165/cfml-only/"; |
| 68 | + var srcDir = testDir & "src/"; |
| 69 | + var larFile = testDir & "test.lar"; |
| 70 | + |
| 71 | + // cleanup from previous runs |
| 72 | + if ( directoryExists( testDir ) ) directoryDelete( testDir, true ); |
| 73 | + directoryCreate( srcDir, true, true ); |
| 74 | + |
| 75 | + // create a simple CFML file — no non-CFML resources |
| 76 | + fileWrite( srcDir & "hello.cfm", "<cfset greeting = 'cfml-only'>" ); |
| 77 | + |
| 78 | + createLarArchive( srcDir, larFile, false ); |
| 79 | + |
| 80 | + // this is where the bug manifests — include from the archive |
| 81 | + include "#variables.testVirtual#/hello.cfm"; |
| 82 | + expect( greeting ).toBe( "cfml-only" ); |
| 83 | + }); |
| 84 | + |
| 85 | + it( "should resolve pages from a LAR archive with mixed content", function() { |
| 86 | + var testDir = getTempDirectory() & "LDEV6165/mixed/"; |
| 87 | + var srcDir = testDir & "src/"; |
| 88 | + var larFile = testDir & "test.lar"; |
| 89 | + |
| 90 | + // cleanup from previous runs |
| 91 | + if ( directoryExists( testDir ) ) directoryDelete( testDir, true ); |
| 92 | + directoryCreate( srcDir, true, true ); |
| 93 | + |
| 94 | + // CFML file plus a static resource |
| 95 | + fileWrite( srcDir & "hello.cfm", "<cfset greeting = 'mixed-content'>" ); |
| 96 | + fileWrite( srcDir & "style.css", "body { color: red; }" ); |
| 97 | + |
| 98 | + createLarArchive( srcDir, larFile, true ); |
| 99 | + |
| 100 | + include "#variables.testVirtual#/hello.cfm"; |
| 101 | + expect( greeting ).toBe( "mixed-content" ); |
| 102 | + }); |
| 103 | + |
| 104 | + }); |
| 105 | + } |
| 106 | + |
| 107 | +} |
0 commit comments