From 7620e7952438c0a41efd3f75e0cedb94d8da3a4c Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 7 Oct 2022 16:39:18 +0200 Subject: [PATCH] debugging with secure websockets tests --- TODO.txt | 7 +++++++ jest.config.js | 2 +- test/helpers/NotificationsClient.ts | 12 ++++++++---- test/surface/notifications.test.ts | 25 ++++++++++++++++++++----- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/TODO.txt b/TODO.txt index 490cd21..4563346 100644 --- a/TODO.txt +++ b/TODO.txt @@ -31,6 +31,8 @@ startSolidNextcloud server And then run the tester interactively and with code mounted from the host: ``` +# docker tag solidtestsuite/solid-crud-tests:v7.0.5 solid-crud-tests + docker run --rm --network=testnet --env COOKIE="$COOKIE_server" --env COOKIE_ALICE="$COOKIE_server" --env COOKIE_BOB="$COOKIE_thirdparty" --env-file ./env-vars-testers.list -it -v /Users/michiel/gh/solid-contrib/solid-crud-tests/test:/app/test --name tester -v /Users/michiel/hevel:/hevel solid-crud-tests /bin/bash ``` @@ -38,3 +40,8 @@ And then inside that: ``` ./node_modules/.bin/jest test/surface/notifications.test.ts ``` + + +For Wh2Ws testing: + +docker exec -it pubsub php server/serverWh2Ws.php \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index d8daf23..386931a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,7 +2,7 @@ module.exports = { roots: ["/test"], preset: "ts-jest", testEnvironment: "node", - testTimeout: 60000, + testTimeout: 6000, verbose: false, runner: "jest-serial-runner", collectCoverage: false, diff --git a/test/helpers/NotificationsClient.ts b/test/helpers/NotificationsClient.ts index 53b6a26..f0e3071 100644 --- a/test/helpers/NotificationsClient.ts +++ b/test/helpers/NotificationsClient.ts @@ -59,7 +59,7 @@ export class NotificationsClient { this.sentHook = []; this.resourceUrl = resourceUrl; this.authFetcher = authFetcher; - this.disabled = !!process.env.SKIP_WPS; + this.disabled = !!process.env.SKIP_WPS && !!process.env.SKIP_SECURE_WEBSOCKETS && !!process.env.SKIP_WEBHOOKS; this.discoveryLinks = { insecureWs: undefined, storageWide: undefined, @@ -77,6 +77,7 @@ export class NotificationsClient { method: "HEAD", }); const linkHeaders = resourceFetchResult.headers.raw()["link"]; + console.log({linkHeaders}); if (Array.isArray(linkHeaders) && linkHeaders.length > 0) { let obj = {}; for (let i = 0; i < linkHeaders.length; i++) { @@ -139,27 +140,30 @@ export class NotificationsClient { } async getReady(): Promise { + console.log('in getReady!'); if (this.disabled) { + console.log('disabled, not getting ready!'); return; } const descriptions = await this.getLinksToNotifications(); + console.log({ descriptions }); if ( typeof descriptions.insecureWs === "string" && - descriptions.insecureWs.length > 0 + descriptions.insecureWs.length > 0 && !process.env.SKIP_WPS ) { // console.log("get ready for insecure websockets"); await this.setupInsecureWs(descriptions.insecureWs); } if ( typeof descriptions.storageWide === "string" && - descriptions.storageWide.length > 0 + descriptions.storageWide.length > 0 && !process.env.SKIP_SECURE_WEBSOCKETS ) { // console.log("get ready for storage wide"); await this.subscribeToChannels(descriptions.storageWide); } if ( typeof descriptions.resourceSpecific === "string" && - descriptions.resourceSpecific.length > 0 + descriptions.resourceSpecific.length > 0 && !process.env.SKIP_WEBHOOKS ) { // console.log("get ready for resource specific"); await this.subscribeToChannels(descriptions.resourceSpecific); diff --git a/test/surface/notifications.test.ts b/test/surface/notifications.test.ts index 4bebbbc..bd9ae4e 100644 --- a/test/surface/notifications.test.ts +++ b/test/surface/notifications.test.ts @@ -48,6 +48,7 @@ describe("Notifications", () => { ); // console.log({ newCookie }); } + console.log("getAuthFetcher", oidcIssuer, newCookie, appOrigin); authFetcher = await getAuthFetcher(oidcIssuer, newCookie, appOrigin); }); describe("When overwriting plain text with plain text using PUT", () => { @@ -124,7 +125,9 @@ describe("Notifications", () => { authFetcher, 8123 // webHooksPort ); + console.log('getting ready'); await notificationsClientResource.getReady(); + console.log('got ready'); const headers = { "Content-Type": "text/plain", }; @@ -170,11 +173,23 @@ describe("Notifications", () => { ifSecureWebsockets( "emits secure websockets notification on the resource", () => { - // FIXME: expect the new format! - // expect(notificationsClientResource.receivedSecure).toEqual( - // expect.arrayContaining([`ack ${resourceUrl}`, `pub ${resourceUrl}`]) - // ); - } + expect(Array.isArray(notificationsClientResource.receivedSecure)).toEqual(true); + expect(notificationsClientResource.receivedSecure.length).toEqual(1); + const msgObj = JSON.parse(notificationsClientResource.receivedSecure[0]); + expect(Array.isArray(msgObj["@context"])).toEqual(true); + expect(Array.isArray(msgObj["type"])).toEqual(true); + expect(Array.isArray(msgObj["object"]["type"])).toEqual(true); + expect( + msgObj["@context"].indexOf( + "https://www.w3.org/ns/solid/notification/v1" + ) + ).not.toEqual(-1); + expect(msgObj["type"][0]).toEqual("Update"); + expect(msgObj["object"]["id"]).toEqual(resourceUrl); + expect( + msgObj["object"]["type"].indexOf("http://www.w3.org/ns/ldp#Resource") + ).not.toEqual(-1); + } ); ifWebhooks( "webhooks advertised using server-wide or resource-specific Link header",