1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- const parsePemCertificate = require('../../../lib/credentials/certificate/parsePemCertificate');
- const APNCertificate = require('../../../lib/credentials/certificate/APNCertificate');
- const fs = require('fs');
- describe('parsePemCertificate', function () {
- describe('with PEM certificate', function () {
- let cert, certProperties;
- before(function () {
- cert = fs.readFileSync('test/credentials/support/cert.pem');
- });
- beforeEach(function () {
- certProperties = parsePemCertificate(cert);
- });
- describe('return value', function () {
- it('is an array', function () {
- expect(certProperties).to.be.an('array');
- });
- it('contains one element', function () {
- expect(certProperties).to.have.length(1);
- });
- describe('certificate [0]', function () {
- it('is an APNCertificate', function () {
- expect(certProperties[0]).to.be.an.instanceof(APNCertificate);
- });
- it('has the correct fingerprint', function () {
- expect(certProperties[0].key().fingerprint()).to.equal(
- '2d594c9861227dd22ba5ae37cc9354e9117a804d'
- );
- });
- });
- });
- });
- describe('with PEM containing multiple certificates', function () {
- let cert, certProperties;
- before(function () {
- cert = fs.readFileSync('test/credentials/support/certIssuerKey.pem');
- });
- beforeEach(function () {
- certProperties = parsePemCertificate(cert);
- });
- it('returns the correct number of certificates', function () {
- expect(certProperties).to.have.length(2);
- });
- describe('certificate [0]', function () {
- it('has the correct fingerprint', function () {
- expect(certProperties[0].key().fingerprint()).to.equal(
- '2d594c9861227dd22ba5ae37cc9354e9117a804d'
- );
- });
- });
- describe('certificate [1]', function () {
- it('has the correct fingerprint', function () {
- expect(certProperties[1].key().fingerprint()).to.equal(
- 'ccff221d67cb3335649f9b4fbb311948af76f4b2'
- );
- });
- });
- });
- describe('with a PKCS#12 file', function () {
- it('throws', function () {
- const pfx = fs.readFileSync('test/credentials/support/certIssuerKey.p12');
- expect(function () {
- parsePemCertificate(pfx);
- }).to.throw('unable to parse certificate, not a valid PEM file');
- });
- });
- describe('with a key', function () {
- it('returns an empty array', function () {
- const key = fs.readFileSync('test/credentials/support/key.pem');
- expect(parsePemCertificate(key)).to.be.empty;
- });
- });
- describe('returns null', function () {
- it('for null', function () {
- expect(parsePemCertificate(null)).to.be.null;
- });
- it('for undefined', function () {
- expect(parsePemCertificate(undefined)).to.be.null;
- });
- });
- });
|