Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bob2402 committed Jun 17, 2024
1 parent 2d794e5 commit 3665ea2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type Relay = {
// space member
get_space_members: func_GetSpaceMembers;
is_space_member: func_IsSpaceMember;
add_space_member: func_AddSpaceMember;
[Symbol.asyncDispose]: () => Promise<void>;
};

Expand Down Expand Up @@ -253,6 +254,7 @@ export async function run(args: {
// space member
get_space_members: get_space_members(db),
is_space_member: is_space_member({ admin: args.admin, db }),
add_space_member: add_space_member(db),
[Symbol.asyncDispose]() {
return shutdown();
},
Expand Down
15 changes: 7 additions & 8 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PrivateKey } from "../nostr.ts/key.ts";
import { sleep } from "https://raw.githubusercontent.com/BlowaterNostr/csp/master/csp.ts";
import { RFC3339 } from "../nostr.ts/_helper.ts";
import { format } from "https://deno.land/[email protected]/datetime/format.ts";
import { prepareSpaceMember } from "../nostr.ts/space-member.ts";

const test_kv = async () => {
try {
Expand Down Expand Up @@ -368,21 +369,20 @@ Deno.test({
name: "Authorization",
// ignore: true,
fn: async (t) => {
const pri = PrivateKey.Generate();
const ctx = InMemoryAccountContext.Generate();
const relay = await run({
admin: pri.toPublicKey(),
admin: ctx.publicKey.hex,
kv: await test_kv(),
default_policy: {
allowed_kinds: "all",
},
auth_required: true,
});
if (relay instanceof Error) fail(relay.message);
const admin = InMemoryAccountContext.FromString(pri.hex) as Signer;

await t.step("admin is always allowed", async () => {
const client = SingleRelayConnection.New(relay.ws_url, {
signer: admin,
signer: ctx,
});
const err = await client.newSub("", {});
assertNotInstanceOf(err, Error);
Expand All @@ -391,10 +391,9 @@ Deno.test({

await t.step("a member is allowed", async () => {
const user = InMemoryAccountContext.Generate();
await relay.set_policy({
kind: NostrKind.TEXT_NOTE,
allow: new Set([user.publicKey.hex]),
});
const spaceMemberEvennt = await prepareSpaceMember(ctx, user.publicKey.hex);
if (spaceMemberEvennt instanceof Error) fail(spaceMemberEvennt.message);
await relay.add_space_member(spaceMemberEvennt);
const client = SingleRelayConnection.New(relay.ws_url, {
signer: user,
});
Expand Down

0 comments on commit 3665ea2

Please sign in to comment.