nostr package: more tests #434

Merged
sistemd merged 4 commits from nostr-package-better-tests into nostr-package-eose 2023-03-27 09:06:17 +00:00
5 changed files with 31 additions and 4 deletions
Showing only changes of commit 43ef562bf3 - Show all commits

View File

@ -9,4 +9,4 @@ EXPOSE 8000
COPY . .
USER $APP_USER
RUN yarn
CMD yarn app /bin/bash -c "rm -rf /usr/src/app/db/* && ./nostr-rs-relay --db /usr/src/app/db"
CMD yarn app /bin/bash -c "rm -rf /usr/src/app/db/* && ./nostr-rs-relay --db /usr/src/app/db --config ./config.toml"

View File

@ -0,0 +1,3 @@
[authorization]
nip42_auth = true
nip42_dms = true

View File

@ -109,8 +109,9 @@ export type IncomingMessage =
| IncomingNotice
| IncomingOk
| IncomingEose
| IncomingAuth
export type IncomingKind = "event" | "notice" | "ok" | "eose"
export type IncomingKind = "event" | "notice" | "ok" | "eose" | "auth"
/**
* Incoming "EVENT" message.
@ -147,6 +148,13 @@ export interface IncomingEose {
subscriptionId: SubscriptionId
}
/**
* Incoming "AUTH" message.
*/
export interface IncomingAuth {
kind: "auth"
}
/**
* A message sent from the client to a relay.
*/
@ -308,6 +316,14 @@ async function parseIncomingMessage(data: string): Promise<IncomingMessage> {
}
}
// TODO This is incomplete
// Handle incoming "AUTH" messages.
if (json[0] === "AUTH") {
return {
kind: "auth",
}
}
throw new ProtocolError(`unknown incoming message: ${data}`)
}

View File

@ -78,8 +78,10 @@ export class Nostr extends EventEmitter {
)
} else if (msg.kind === "eose") {
this.emit("eose", msg.subscriptionId, this)
} else if (msg.kind === "auth") {
// TODO This is incomplete
} else {
throw new ProtocolError(`invalid message ${msg}`)
throw new ProtocolError(`invalid message ${JSON.stringify(msg)}`)
}
} catch (err) {
this.emit("error", err, this)

View File

@ -37,6 +37,9 @@ describe("dm", async function () {
assert.equal(await event.getMessage(subscriberSecret), message)
}
publisher.close()
subscriber.close()
done()
} catch (e) {
done(e)
@ -63,7 +66,7 @@ describe("dm", async function () {
})
// Test that an unintended recipient still receives the direct message event, but cannot decrypt it.
it.only("to unintended recipient", (done) => {
it("to unintended recipient", (done) => {
setup(done).then(
({
publisher,
@ -98,6 +101,9 @@ describe("dm", async function () {
)
}
publisher.close()
subscriber.close()
done()
} catch (e) {
done(e)