load.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const fs = require('fs');
  2. describe('loadCredentials', function () {
  3. let pfx, cert, key, loadCredentials;
  4. before(function () {
  5. pfx = fs.readFileSync('test/support/initializeTest.pfx');
  6. cert = fs.readFileSync('test/support/initializeTest.crt');
  7. key = fs.readFileSync('test/support/initializeTest.key');
  8. const resolve = require('../../../lib/credentials/resolve');
  9. loadCredentials = require('../../../lib/credentials/certificate/load')({ resolve });
  10. });
  11. it('should load a pfx file from disk', function () {
  12. return expect(
  13. loadCredentials({ pfx: 'test/support/initializeTest.pfx' }).pfx.toString()
  14. ).to.equal(pfx.toString());
  15. });
  16. it('should provide pfx data from memory', function () {
  17. return expect(loadCredentials({ pfx: pfx }).pfx.toString()).to.equal(pfx.toString());
  18. });
  19. it('should provide pfx data explicitly passed in pfxData parameter', function () {
  20. return expect(loadCredentials({ pfxData: pfx }).pfx.toString()).to.equal(pfx.toString());
  21. });
  22. it('should load a certificate from disk', function () {
  23. return expect(
  24. loadCredentials({ cert: 'test/support/initializeTest.crt', key: null }).cert.toString()
  25. ).to.equal(cert.toString());
  26. });
  27. it('should provide a certificate from a Buffer', function () {
  28. return expect(loadCredentials({ cert: cert, key: null }).cert.toString()).to.equal(
  29. cert.toString()
  30. );
  31. });
  32. it('should provide a certificate from a String', function () {
  33. return expect(loadCredentials({ cert: cert.toString(), key: null }).cert).to.equal(
  34. cert.toString()
  35. );
  36. });
  37. it('should provide certificate data explicitly passed in the certData parameter', function () {
  38. return expect(loadCredentials({ certData: cert, key: null }).cert.toString()).to.equal(
  39. cert.toString()
  40. );
  41. });
  42. it('should load a key from disk', function () {
  43. return expect(
  44. loadCredentials({ cert: null, key: 'test/support/initializeTest.key' }).key.toString()
  45. ).to.equal(key.toString());
  46. });
  47. it('should provide a key from a Buffer', function () {
  48. return expect(loadCredentials({ cert: null, key: key }).key.toString()).to.equal(
  49. key.toString()
  50. );
  51. });
  52. it('should provide a key from a String', function () {
  53. return expect(loadCredentials({ cert: null, key: key.toString() }).key).to.equal(
  54. key.toString()
  55. );
  56. });
  57. it('should provide key data explicitly passed in the keyData parameter', function () {
  58. return expect(loadCredentials({ cert: null, keyData: key }).key.toString()).to.equal(
  59. key.toString()
  60. );
  61. });
  62. it('should inclue the passphrase in the resolved value', function () {
  63. return expect(loadCredentials({ passphrase: 'apntest' }).passphrase).to.equal('apntest');
  64. });
  65. });