-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
11 changed files
with
460 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { assertEquals } from "jsr:@std/assert@^0.218.2"; | ||
import { Service } from "../mod.ts"; | ||
import { Actor } from "../vocab/actor.ts"; | ||
import { Application, Endpoints, Group, Person } from "../vocab/vocab.ts"; | ||
import { extractInboxes } from "./send.ts"; | ||
|
||
Deno.test("extractInboxes()", () => { | ||
const recipients: Actor[] = [ | ||
new Person({ | ||
id: new URL("https://example.com/alice"), | ||
inbox: new URL("https://example.com/alice/inbox"), | ||
endpoints: new Endpoints({ | ||
sharedInbox: new URL("https://example.com/inbox"), | ||
}), | ||
}), | ||
new Application({ | ||
id: new URL("https://example.com/app"), | ||
inbox: new URL("https://example.com/app/inbox"), | ||
endpoints: new Endpoints({ | ||
sharedInbox: new URL("https://example.com/inbox"), | ||
}), | ||
}), | ||
new Group({ | ||
id: new URL("https://example.org/group"), | ||
inbox: new URL("https://example.org/group/inbox"), | ||
}), | ||
new Service({ | ||
id: new URL("https://example.net/service"), | ||
inbox: new URL("https://example.net/service/inbox"), | ||
endpoints: new Endpoints({ | ||
sharedInbox: new URL("https://example.net/inbox"), | ||
}), | ||
}), | ||
]; | ||
let inboxes = extractInboxes({ recipients }); | ||
assertEquals( | ||
inboxes, | ||
new Set([ | ||
new URL("https://example.com/alice/inbox"), | ||
new URL("https://example.com/app/inbox"), | ||
new URL("https://example.org/group/inbox"), | ||
new URL("https://example.net/service/inbox"), | ||
]), | ||
); | ||
inboxes = extractInboxes({ recipients, preferSharedInbox: true }); | ||
assertEquals( | ||
inboxes, | ||
new Set([ | ||
new URL("https://example.com/inbox"), | ||
new URL("https://example.org/group/inbox"), | ||
new URL("https://example.net/inbox"), | ||
]), | ||
); | ||
}); |
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,60 @@ | ||
import { assertThrows } from "jsr:@std/assert@^0.218.2"; | ||
import { validateCryptoKey } from "./key.ts"; | ||
|
||
Deno.test("validateCryptoKey()", async () => { | ||
const pkcs1v15 = await crypto.subtle.generateKey( | ||
{ | ||
name: "RSASSA-PKCS1-v1_5", | ||
modulusLength: 2048, | ||
publicExponent: new Uint8Array([1, 0, 1]), | ||
hash: "SHA-256", | ||
}, | ||
true, | ||
["sign", "verify"], | ||
); | ||
validateCryptoKey(pkcs1v15.privateKey, "private"); | ||
validateCryptoKey(pkcs1v15.privateKey); | ||
validateCryptoKey(pkcs1v15.publicKey, "public"); | ||
validateCryptoKey(pkcs1v15.publicKey); | ||
|
||
assertThrows( | ||
() => validateCryptoKey(pkcs1v15.privateKey, "public"), | ||
TypeError, | ||
"The key is not a public key.", | ||
); | ||
assertThrows( | ||
() => validateCryptoKey(pkcs1v15.publicKey, "private"), | ||
TypeError, | ||
"The key is not a private key.", | ||
); | ||
|
||
const ecdsa = await crypto.subtle.generateKey( | ||
{ | ||
name: "ECDSA", | ||
namedCurve: "P-256", | ||
}, | ||
true, | ||
["sign", "verify"], | ||
); | ||
assertThrows( | ||
() => validateCryptoKey(ecdsa.publicKey), | ||
TypeError, | ||
"only RSASSA-PKCS1-v1_5", | ||
); | ||
|
||
const pkcs1v15Sha512 = await crypto.subtle.generateKey( | ||
{ | ||
name: "RSASSA-PKCS1-v1_5", | ||
modulusLength: 2048, | ||
publicExponent: new Uint8Array([1, 0, 1]), | ||
hash: "SHA-512", | ||
}, | ||
true, | ||
["sign", "verify"], | ||
); | ||
assertThrows( | ||
() => validateCryptoKey(pkcs1v15Sha512.privateKey), | ||
TypeError, | ||
"hash algorithm must be SHA-256", | ||
); | ||
}); |
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
Oops, something went wrong.