-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
107 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
import * as TestCertStore from "@ndn/keychain/test-fixture/cert-store"; | ||
import * as TestKeyStore from "@ndn/keychain/test-fixture/key-store"; | ||
import { dirSync as tmpDir } from "tmp"; | ||
import { beforeEach, test } from "vitest"; | ||
import { makeTmpDir } from "@ndn/util/test-fixture/tmp"; | ||
import { test } from "vitest"; | ||
|
||
import { NdnsecKeyChain } from ".."; | ||
|
||
let home: string; | ||
beforeEach(() => { | ||
const { name, removeCallback } = tmpDir({ unsafeCleanup: true }); | ||
home = name; | ||
return removeCallback; | ||
}); | ||
|
||
test.runIf(NdnsecKeyChain.supported)("KeyStore", async () => { | ||
using tmpDir = makeTmpDir(); | ||
const enabled: TestKeyStore.Enable = { HMAC: false, Ed25519: false }; | ||
const keyChain = new NdnsecKeyChain({ home }); | ||
const keyChain = new NdnsecKeyChain({ home: tmpDir.name }); | ||
const record = await TestKeyStore.execute(keyChain, enabled); | ||
TestKeyStore.check(record, enabled); | ||
}, 20000); | ||
|
||
test.runIf(NdnsecKeyChain.supported)("CertStore", async () => { | ||
const keyChain = new NdnsecKeyChain({ home }); | ||
using tmpDir = makeTmpDir(); | ||
const keyChain = new NdnsecKeyChain({ home: tmpDir.name }); | ||
const record = await TestCertStore.execute(keyChain); | ||
TestCertStore.check(record); | ||
}, 20000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import path from "node:path"; | ||
|
||
import { dirSync as tmpDir, tmpNameSync as tmpName } from "tmp"; | ||
import { sync as write } from "write"; | ||
|
||
/** Create a temporary directory. */ | ||
export function makeTmpDir(): TmpDir { | ||
const { name, removeCallback } = tmpDir({ prefix: "tmp-NDNts-", unsafeCleanup: true }); | ||
const filename = () => tmpName({ dir: name }); | ||
return { | ||
name, | ||
join: (...segments) => path.join(name, ...segments), | ||
filename, | ||
createFile: (content) => { | ||
const fn = filename(); | ||
write(fn, content); | ||
return fn; | ||
}, | ||
[Symbol.dispose]: removeCallback, | ||
}; | ||
} | ||
|
||
/** | ||
* Temporary directory. | ||
* | ||
* @remarks | ||
* Disposing this object deletes the directory and its content. | ||
*/ | ||
export interface TmpDir extends Disposable { | ||
/** Directory path. */ | ||
readonly name: string; | ||
|
||
/** Join with additional path segment(s). */ | ||
join: (...segments: string[]) => string; | ||
|
||
/** | ||
* Generate random filename within the directory. | ||
* @returns Full filename. | ||
*/ | ||
filename: () => string; | ||
|
||
/** | ||
* Write content to a file within the directory. | ||
* @returns Full filename. | ||
*/ | ||
createFile: (content: string | Uint8Array) => string; | ||
} |
This file was deleted.
Oops, something went wrong.