APNKey.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const APNKey = require('../../../lib/credentials/certificate/APNKey');
  2. const forge = require('node-forge');
  3. const fs = require('fs');
  4. describe('APNKey', function () {
  5. it('initialises with a node-forge public key', function () {
  6. expect(new APNKey({ n: 12345, e: 65536 })).to.be.an.instanceof(APNKey);
  7. });
  8. describe('throws', function () {
  9. it('missing modulus', function () {
  10. expect(function () {
  11. new APNKey({ e: 65536 });
  12. }).to.throw('key is not a valid public key');
  13. });
  14. it('missing exponent', function () {
  15. expect(function () {
  16. new APNKey({ n: 12345 });
  17. }).to.throw('key is not a valid public key');
  18. });
  19. it('undefined', function () {
  20. expect(function () {
  21. new APNKey();
  22. }).to.throw('key is not a valid public key');
  23. });
  24. });
  25. describe('fingerprint', function () {
  26. it('returns the fingerprint of the public key', function () {
  27. const keyPem = fs.readFileSync('test/credentials/support/key.pem');
  28. const apnKey = new APNKey(forge.pki.decryptRsaPrivateKey(keyPem));
  29. expect(apnKey.fingerprint()).to.equal('2d594c9861227dd22ba5ae37cc9354e9117a804d');
  30. });
  31. });
  32. });