forked from libapps/libapps-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib_credential_cache_tests.js
More file actions
63 lines (57 loc) · 2.13 KB
/
lib_credential_cache_tests.js
File metadata and controls
63 lines (57 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2018 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Test suite for the session-local, encrypted cache.
*/
import {lib} from '../../libdot/index.js';
import {CredentialCache} from './lib_credential_cache.js';
/**
* Verify that the cache remains enabled after being enabled once.
*/
it('enabled', () => {
const cache = new CredentialCache();
assert.isNull(cache.isEnabled());
cache.setEnabled(true);
assert.isTrue(cache.isEnabled());
cache.setEnabled(false);
assert.isTrue(cache.isEnabled());
});
/**
* Verify that the cache remains disabled after being disabled once.
*/
it('disabled', () => {
const cache = new CredentialCache();
assert.isNull(cache.isEnabled());
cache.setEnabled(false);
assert.isFalse(cache.isEnabled());
cache.setEnabled(true);
assert.isFalse(cache.isEnabled());
});
/**
* Simulate and verify a typical workflow consisting of store and retrieve
* operations.
*/
it('workflow', async () => {
const cache = new CredentialCache();
const keyId1 = 'AABBCCDDEEFF';
const keyId2 = 'FFEEDDCCBBAA';
await cache.store('reader_1' + keyId1, new Uint8Array([1, 2, 4, 8]));
assert.deepStrictEqual(await cache.retrieve('foobar_1' + keyId1), null);
assert.deepStrictEqual(await cache.retrieve('reader_1' + keyId2), null);
assert.deepStrictEqual(
Array.from(lib.notNull(await cache.retrieve('reader_1' + keyId1))),
[1, 2, 4, 8]);
assert.deepStrictEqual(await cache.retrieve('reader_1' + keyId1), null);
await cache.store('reader_2' + keyId1, new Uint8Array([1, 3, 9, 27]));
await cache.store('reader_1' + keyId2, new Uint8Array([1, 5, 25]));
await cache.store('reader_1' + keyId2, new Uint8Array([1, 7]));
assert.deepStrictEqual(
Array.from(lib.notNull(await cache.retrieve('reader_1' + keyId2))),
[1, 7]);
assert.deepStrictEqual(await cache.retrieve('reader_1' + keyId2), null);
await cache.store('reader_1' + keyId2, new Uint8Array([1, 5, 25]));
assert.deepStrictEqual(
Array.from(lib.notNull(await cache.retrieve('reader_1' + keyId2))),
[1, 5, 25]);
});