Skip to content

Commit 09bf5c4

Browse files
committed
fix: Workaround for Lucee's incorrect toBase64 behavior
Workaround for where `toBase64` returns a different value on the first call then subsequent calls. We call `toBase64` once in our code so the user does not have to deal with this bug. See https://luceeserver.atlassian.net/browse/LDEV-3964
1 parent 342d355 commit 09bf5c4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

models/TOTP.cfc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ component singleton accessors="true" {
3434
config[ "secret" ] = generateSecret( arguments.length );
3535
config[ "url" ] = generateUrl( arguments.email, arguments.issuer, config.secret );
3636
config[ "qrCode" ] = generateQRCode( config.url, arguments.width, arguments.height );
37+
38+
// Lucee does not generate the same base64 string on the first call of `toBase64`.
39+
// We call it here once so that user-land code gets the correct value if they call `toBase64`.
40+
// https://luceeserver.atlassian.net/browse/LDEV-3964
41+
toBase64( config[ "qrCode" ] );
42+
3743
return config;
3844
}
3945

tests/specs/unit/TOTPSpec.cfc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ component extends="testbox.system.BaseSpec" {
212212
expect( isImage( config.qrCode ) ).toBeTrue( "An image should have been returned" );
213213
expect( variables.totp.getBarcodeService().decode( config.qrCode ) ).toBe( config.url );
214214
} );
215+
216+
it( "generates the same base64 string from the QR code multiple times", function() {
217+
var email = "john@example.com";
218+
var issuer = "Example Company";
219+
var config = variables.totp.generate( email, issuer );
220+
var firstBase64 = toBase64( config.qrCode );
221+
var secondBase64 = toBase64( config.qrCode );
222+
expect( firstBase64 ).toBe(
223+
secondBase64,
224+
"toBase64 should return the same value every time it is called."
225+
);
226+
} );
215227
} );
216228
}
217229

0 commit comments

Comments
 (0)