-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to ensure publicity syncing works for +s modes (#1698)
* PgDataStore: Fix syntax of array parameters Arrays passed as query parameters become PostgreSQL arrays. However, `foo IN $1` is not valid syntax, as `IN` can only be used with subqueries (`foo IN (SELECT ...)`) and lists (`foo IN ($1, $2)`), which require parentheses. `foo IN ($1)` is interpreted as a list and the expression is compared with the whole array, not checked against its members. The correct syntax for checking if a value matches any member of an array parameter is `foo = ANY($1)`, described in https://www.postgresql.org/docs/15/functions-comparisons.html#id-1.5.8.30.16. Fix `getIrcChannelsForRoomIds` and `getRoomsVisibility`. While we're at it, replace `getMappingsForChannelByOrigin`'s workable but awkward building of a parameter list. Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> * Add tests for publicity-syncing * Await publicity * Refactor to fix publicity sync * Refactor * changelog * Ensure PgDataStore returns private for missing entries --------- Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com> Co-authored-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
- Loading branch information
Showing
8 changed files
with
119 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix SQL syntax errors in the PostgreSQL data store. |
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 @@ | ||
Add tests that cover publicity syncing behaviour. |
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,65 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { Request } from "matrix-appservice-bridge"; | ||
import { IrcBridge } from "../../lib/bridge/IrcBridge"; | ||
import { BridgeRequest } from "../../lib/models/BridgeRequest"; | ||
import envBundle from "../util/env-bundle"; | ||
|
||
describe("Publicity Syncing", function() { | ||
const {env, roomMapping, test} = envBundle(); | ||
|
||
beforeEach(async () => { | ||
await test.beforeEach(env); | ||
|
||
env.ircMock._autoConnectNetworks( | ||
roomMapping.server, roomMapping.botNick, roomMapping.server | ||
); | ||
env.ircMock._autoJoinChannels( | ||
roomMapping.server, roomMapping.botNick, roomMapping.channel | ||
); | ||
|
||
await test.initEnv(env); | ||
}); | ||
|
||
afterEach(async () => test.afterEach(env)); | ||
|
||
it("should ensure rooms with no visibility state are private", async () => { | ||
const ircBridge: IrcBridge = env.ircBridge as IrcBridge; | ||
const store = ircBridge.getStore(); | ||
const roomVis = await store.getRoomsVisibility([roomMapping.roomId]); | ||
expect(roomVis.get(roomMapping.roomId)).toBe('private'); | ||
}); | ||
|
||
it("should ensure rooms with +s channels are set to private visibility", async () => { | ||
const ircBridge: IrcBridge = env.ircBridge as IrcBridge; | ||
const store = ircBridge.getStore(); | ||
// Ensure opposite state | ||
await store.setRoomVisibility(roomMapping.roomId, "public"); | ||
const req = new BridgeRequest(new Request({ | ||
data: { | ||
isFromIrc: true, | ||
} | ||
})); | ||
const server = ircBridge.getServer(roomMapping.server)!; | ||
await ircBridge.ircHandler.roomAccessSyncer.onMode( | ||
req, server, roomMapping.channel, "", "s", true, null | ||
); | ||
const roomVis = await store.getRoomsVisibility([roomMapping.roomId]); | ||
expect(roomVis.get(roomMapping.roomId)).toBe('private'); | ||
}); | ||
|
||
it("should ensure rooms with -s channels are set to public visibility", async () => { | ||
const ircBridge: IrcBridge = env.ircBridge as IrcBridge; | ||
const store = ircBridge.getStore(); | ||
const req = new BridgeRequest(new Request({ | ||
data: { | ||
isFromIrc: true, | ||
} | ||
})); | ||
const server = ircBridge.getServer(roomMapping.server)!; | ||
await ircBridge.ircHandler.roomAccessSyncer.onMode( | ||
req, server, roomMapping.channel, "", "s", false, null | ||
); | ||
const roomVis = await store.getRoomsVisibility([roomMapping.roomId]); | ||
expect(roomVis.get(roomMapping.roomId)).toBe('public'); | ||
}); | ||
}); |
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