Skip to content

Commit

Permalink
unit test added for encodeCertStringToBase64
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalshit27 committed Jan 7, 2025
1 parent 40d6a09 commit cc6b9bd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
sanitize,
stripIdentifiers,
toConfigFn,
encodeCertStringToBase64,
} from '../src/utils';

const mockConfigFn = () => {};
Expand Down Expand Up @@ -269,4 +270,23 @@ describe('#utils', function () {
expect(mapClientID2NameSorted(null, null)).deep.equal([]);
});
});

describe('encodeCertStringToBase64', () => {
it('should encode certificate string to Base64', () => {
const cert =
'-----BEGIN CERTIFICATE-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7\n-----END CERTIFICATE-----';
const expectedBase64 = Buffer.from(cert).toString('base64');
expect(encodeCertStringToBase64(cert)).to.equal(expectedBase64);
});

it('should return the original string if it does not start with "-----BEGIN CERTIFICATE-----"', () => {
const nonCertString = 'This is not a certificate';
expect(encodeCertStringToBase64(nonCertString)).to.equal(nonCertString);
});

it('should return the original string if it is null or undefined', () => {
expect(encodeCertStringToBase64(null)).to.equal(null);
expect(encodeCertStringToBase64(undefined)).to.equal(undefined);
});
});
});

0 comments on commit cc6b9bd

Please sign in to comment.