UNPKG

3.29 kBJavaScriptView Raw
1/**
2 * Tests windowslib's certs module.
3 *
4 * @copyright
5 * Copyright (c) 2016 by Appcelerator, Inc. All Rights Reserved.
6 *
7 * @license
8 * Licensed under the terms of the Apache Public License.
9 * Please see the LICENSE included with this distribution for details.
10 */
11
12const
13 fs = require('fs'),
14 path = require('path'),
15 windowslib = require('..'),
16 CERT_FILE = path.join(__dirname, 'Windows_TemporaryKey.pfx');
17
18describe('certs', function () {
19 it('namespace should be an object', function () {
20 should(windowslib.certs).be.an.Object;
21 });
22
23 it('parseCertUtilOutput() retrieves sha1 thumbprint from Italian output', function (done) {
24 var output = "================ Certificato 0 ================\r\n" +
25 "================ Inizio nidificazione livello 1 ================\r\n" +
26 "Elemento 0:\r\n" +
27 "Numero di serie: 11b6d24418117bb246138341b49e9bfe\r\n" +
28 "Autorità emittente: CN=FEC38FFF-D0C5-4AA7-9644-5E96476CB034\r\n" +
29 " NotBefore: 08/01/2016 10:53\r\n" +
30 " NotAfter: 08/01/2018 01:00\r\n" +
31 "Soggetto: CN=FEC38FFF-D0C5-4AA7-9644-5E96476CB034\r\n" +
32 "La firma elettronica corrisponde alla chiave pubblica\r\n" +
33 "Certificato radice: soggetto corrispondente all'autorità emittente\r\n" +
34 "Hash certificato (sha1): f4 23 1f 8e 13 c7 fa 6f 22 14 dd 54 59 8e 10 e4 25 3a 40 7a\r\n" +
35 "---------------- Fine nidificazione livello 1 ----------------\r\n" +
36 " Provider = Microsoft Strong Cryptographic Provider\r\n" +
37 "Verifica firma riuscita\r\n" +
38 "CertUtil: - Esecuzione comando dump riuscita.";
39 windowslib.certs.test.parseCertUtilOutput(CERT_FILE, output, function (err, value) {
40 if (err) {
41 return done(err);
42 }
43
44 should(value).equal('F4231F8E13C7FA6F2214DD54598E10E4253A407A');
45
46 done();
47 });
48 });
49
50 it('parseCertUtilOutput() retrieves sha1 thumbprint from English output', function (done) {
51 var output = "Certificates: Not Encrypted\r\n" +
52 "================ Certificate 0 ================\r\n" +
53 "================ Begin Nesting Level 1 ================\r\n" +
54 "Element 0:\r\n" +
55 "Serial Number: ae0bba023dbbe5ac42782735199df0fc\r\n" +
56 "Issuer: CN=CMake Test Cert\r\n" +
57 " NotBefore: 1/1/2014 3:00 AM\r\n" +
58 " NotAfter: 1/1/2100 3:00 AM\r\n" +
59 "Subject: CN=CMake Test Cert\r\n" +
60 "Signature matches Public Key\r\n" +
61 "Root Certificate: Subject matches Issuer\r\n" +
62 "Cert Hash(sha1): f6 3a ac 84 a0 88 4c db 01 26 c3 cd ea 99 1e 36 df 06 4b 3e\r\n" +
63 "---------------- End Nesting Level 1 ----------------\r\n" +
64 " Provider = Microsoft Strong Cryptographic Provider\r\n" +
65 "Signature test passed\r\n" +
66 "CertUtil: -dump command completed successfully..";
67 windowslib.certs.test.parseCertUtilOutput(CERT_FILE, output, function (err, value) {
68 if (err) {
69 return done(err);
70 }
71
72 should(value).equal('F63AAC84A0884CDB0126C3CDEA991E36DF064B3E');
73
74 done();
75 });
76 });
77
78 (process.platform === 'win32' ? it : it.skip)('thumbprint retrieves sha1 thumbprint of cmake temp key with no password', function (done) {
79 this.timeout(5000);
80 this.slow(4000);
81
82 windowslib.certs.thumbprint(CERT_FILE, null, function (err, value) {
83 if (err) {
84 return done(err);
85 }
86
87 should(value).equal('F63AAC84A0884CDB0126C3CDEA991E36DF064B3E');
88
89 done();
90 });
91 });
92});