@@ -2,7 +2,8 @@ import { HttpAgent, fromHex } from "@dfinity/agent";
2
2
import { Principal } from "@dfinity/principal" ;
3
3
import { isMessageBodyValid , randomBigInt , safeExecute } from "./utils" ;
4
4
import { ClientIncomingMessage } from "./types" ;
5
- import logger from "./logger" ;
5
+ import { logger } from "./logger" ;
6
+ import { MAX_CERTIFICATE_AGE_IN_MINUTES } from "./test/constants" ;
6
7
7
8
// the canister from which the correct data were generated
8
9
const canisterId = Principal . fromText ( "bnz7o-iuaaa-aaaaa-qaaaa-cai" ) ;
@@ -15,8 +16,6 @@ const messageToVerify: ClientIncomingMessage = {
15
16
cert : new Uint8Array ( fromHex ( "d9d9f7a2647472656583018301830183024863616e6973746572830183024a8000000000100000010183018301830183024e6365727469666965645f646174618203582087be17d7ba688bc4fb13d61f3d8d5642df92536e40da98facba7ba0450ea59e082045820f8d20e36feb79f8495eb4c632b7a04171599957c8c267f55b2156d89b5c1e424820458200d3dc76c69e69f12678a2e9a5a6859579ceb28350608e69f1902055650edaf7f820458209e5663705fa61a6ca53ee4a61daa4621e8ece0febd99b334d0ae625aad9f3f6e8204582077d28a3053cd3845a065a879ce36849add41cae9e6a56d452e328194b38e15ec82045820932e7cd3d24b95ff6c0fea6086fc624ee43b0875101777e089ba915ef7ded93d82045820fbb733f900879885afed4ace8eb90b19245f8386e7537769c072e9fded13c6ad830182045820ae29f371a7ae2a4af8bb125ef23486745500f8cb31a02c35cc7155053b67cce683024474696d6582034992da96e7ae90a2ba17697369676e61747572655830932828f169fdce98969c417666f38002e2826081deb756e94c73091a1b7c0455f6c2f3ccc509ab576c8e6f8753b7d85b" ) ) ,
16
17
tree : new Uint8Array ( fromHex ( "d9d9f7830249776562736f636b657483025854737164666c2d6d72346b6d2d3268666a792d67616a716f2d78717668372d6866346d662d6e726134692d336974366c2d6e656177342d736f6f6c772d7461655f303030303030303030303030303030303030303082035820215b2aae42ccf90c6fd928fec029d0b9308e97d0c40f8772100a30097b004bb5" ) ) ,
17
18
} ;
18
- // the max age of the certificate. Since we're using pre-generated certificates, we need to set it really far in the future
19
- const maxCertificateAgeInMinutes = 5 * 60 * 24 * 365 ; // 5 years
20
19
21
20
const agent = HttpAgent . createSync ( ) ;
22
21
agent . rootKey = localReplicaRootKey ;
@@ -30,7 +29,7 @@ describe("Utils of the IcWebSocket", () => {
30
29
messageToVerify . cert ,
31
30
messageToVerify . tree ,
32
31
agent ,
33
- maxCertificateAgeInMinutes ,
32
+ MAX_CERTIFICATE_AGE_IN_MINUTES ,
34
33
) ;
35
34
36
35
expect ( isValid ) . toBe ( true ) ;
@@ -44,7 +43,7 @@ describe("Utils of the IcWebSocket", () => {
44
43
messageToVerify . cert ,
45
44
messageToVerify . tree ,
46
45
agent ,
47
- maxCertificateAgeInMinutes ,
46
+ MAX_CERTIFICATE_AGE_IN_MINUTES ,
48
47
) ) . rejects . toThrow ( "Could not find certified data for this canister in the certificate." ) ;
49
48
} ) ;
50
49
@@ -56,7 +55,7 @@ describe("Utils of the IcWebSocket", () => {
56
55
messageToVerify . cert ,
57
56
messageToVerify . tree ,
58
57
agent ,
59
- maxCertificateAgeInMinutes ,
58
+ MAX_CERTIFICATE_AGE_IN_MINUTES ,
60
59
) ;
61
60
62
61
expect ( isValid ) . toBe ( false ) ;
@@ -70,7 +69,7 @@ describe("Utils of the IcWebSocket", () => {
70
69
messageToVerify . cert ,
71
70
messageToVerify . tree ,
72
71
agent ,
73
- maxCertificateAgeInMinutes ,
72
+ MAX_CERTIFICATE_AGE_IN_MINUTES ,
74
73
) ;
75
74
76
75
expect ( isValid ) . toBe ( false ) ;
@@ -84,7 +83,7 @@ describe("Utils of the IcWebSocket", () => {
84
83
new Uint8Array ( [ 0 , 1 , 2 , 3 ] ) ,
85
84
messageToVerify . tree ,
86
85
agent ,
87
- maxCertificateAgeInMinutes ,
86
+ MAX_CERTIFICATE_AGE_IN_MINUTES ,
88
87
) ;
89
88
90
89
expect ( isValid ) . toBe ( false ) ;
@@ -99,7 +98,7 @@ describe("Utils of the IcWebSocket", () => {
99
98
// another tree, valid but not the same as the one used to generate the data
100
99
fromHex ( "d9d9f7830249776562736f636b657483025854737164666c2d6d72346b6d2d3268666a792d67616a716f2d78717668372d6866346d662d6e726134692d336974366c2d6e656177342d736f6f6c772d7461655f3030303030303030303030303030303030303030820358200a621494d244cd4426e1f3c2ac6942bb21a5312f613f534e6da5182571757403" ) ,
101
100
agent ,
102
- maxCertificateAgeInMinutes ,
101
+ MAX_CERTIFICATE_AGE_IN_MINUTES ,
103
102
) ;
104
103
105
104
expect ( isValid ) . toBe ( false ) ;
@@ -114,7 +113,7 @@ describe("Utils of the IcWebSocket", () => {
114
113
messageToVerify . tree ,
115
114
// the default agent uses the mainnet replica root key
116
115
new HttpAgent ( ) ,
117
- maxCertificateAgeInMinutes ,
116
+ MAX_CERTIFICATE_AGE_IN_MINUTES ,
118
117
) ;
119
118
120
119
expect ( isValid ) . toBe ( false ) ;
0 commit comments