diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-30 10:03:09 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | a4995eb7ac5745f62604d70f7b2225ff33916d49 (patch) | |
tree | 2dbed723d3f5a539e8f0847d914723cd7543b1b2 /server/tests | |
parent | e9b0fa5c16ca196a3ba3267af4008782a3e86875 (diff) | |
download | PeerTube-a4995eb7ac5745f62604d70f7b2225ff33916d49.tar.gz PeerTube-a4995eb7ac5745f62604d70f7b2225ff33916d49.tar.zst PeerTube-a4995eb7ac5745f62604d70f7b2225ff33916d49.zip |
Add ability to unregister plugin auths
Diffstat (limited to 'server/tests')
4 files changed, 80 insertions, 4 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js b/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js index 91c67e550..c65b8d3a8 100644 --- a/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js | |||
@@ -1,6 +1,8 @@ | |||
1 | async function register ({ | 1 | async function register ({ |
2 | registerExternalAuth, | 2 | registerExternalAuth, |
3 | peertubeHelpers | 3 | peertubeHelpers, |
4 | settingsManager, | ||
5 | unregisterExternalAuth | ||
4 | }) { | 6 | }) { |
5 | { | 7 | { |
6 | const result = registerExternalAuth({ | 8 | const result = registerExternalAuth({ |
@@ -53,6 +55,12 @@ async function register ({ | |||
53 | } | 55 | } |
54 | }) | 56 | }) |
55 | } | 57 | } |
58 | |||
59 | settingsManager.onSettingsChange(settings => { | ||
60 | if (settings.disableKefka) { | ||
61 | unregisterExternalAuth('external-auth-2') | ||
62 | } | ||
63 | }) | ||
56 | } | 64 | } |
57 | 65 | ||
58 | async function unregister () { | 66 | async function unregister () { |
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js index 9fc12a3e3..f58faa847 100644 --- a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js +++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js | |||
@@ -1,6 +1,8 @@ | |||
1 | async function register ({ | 1 | async function register ({ |
2 | registerIdAndPassAuth, | 2 | registerIdAndPassAuth, |
3 | peertubeHelpers | 3 | peertubeHelpers, |
4 | settingsManager, | ||
5 | unregisterIdAndPassAuth | ||
4 | }) { | 6 | }) { |
5 | registerIdAndPassAuth({ | 7 | registerIdAndPassAuth({ |
6 | authName: 'spyro-auth', | 8 | authName: 'spyro-auth', |
@@ -47,6 +49,12 @@ async function register ({ | |||
47 | return null | 49 | return null |
48 | } | 50 | } |
49 | }) | 51 | }) |
52 | |||
53 | settingsManager.onSettingsChange(settings => { | ||
54 | if (settings.disableSpyro) { | ||
55 | unregisterIdAndPassAuth('spyro-auth') | ||
56 | } | ||
57 | }) | ||
50 | } | 58 | } |
51 | 59 | ||
52 | async function unregister () { | 60 | async function unregister () { |
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index a72b2829b..312561538 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts | |||
@@ -16,7 +16,9 @@ import { | |||
16 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
17 | uninstallPlugin, | 17 | uninstallPlugin, |
18 | updateMyUser, | 18 | updateMyUser, |
19 | wait | 19 | wait, |
20 | userLogin, | ||
21 | updatePluginSettings | ||
20 | } from '../../../shared/extra-utils' | 22 | } from '../../../shared/extra-utils' |
21 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | 23 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' |
22 | 24 | ||
@@ -258,6 +260,40 @@ describe('Test external auth plugins', function () { | |||
258 | await getMyUserInformation(server.url, kefkaAccessToken, 401) | 260 | await getMyUserInformation(server.url, kefkaAccessToken, 401) |
259 | }) | 261 | }) |
260 | 262 | ||
263 | it('Should unregister external-auth-2 and do not login existing Kefka', async function () { | ||
264 | await updatePluginSettings({ | ||
265 | url: server.url, | ||
266 | accessToken: server.accessToken, | ||
267 | npmName: 'peertube-plugin-test-external-auth-one', | ||
268 | settings: { disableKefka: true } | ||
269 | }) | ||
270 | |||
271 | await userLogin(server, { username: 'kefka', password: 'fake' }, 400) | ||
272 | |||
273 | await loginExternal({ | ||
274 | server, | ||
275 | npmName: 'test-external-auth-one', | ||
276 | authName: 'external-auth-2', | ||
277 | query: { | ||
278 | username: 'kefka' | ||
279 | }, | ||
280 | username: 'kefka', | ||
281 | statusCodeExpected: 404 | ||
282 | }) | ||
283 | }) | ||
284 | |||
285 | it('Should have disabled this auth', async function () { | ||
286 | const res = await getConfig(server.url) | ||
287 | |||
288 | const config: ServerConfig = res.body | ||
289 | |||
290 | const auths = config.plugin.registeredExternalAuths | ||
291 | expect(auths).to.have.lengthOf(2) | ||
292 | |||
293 | const auth1 = auths.find(a => a.authName === 'external-auth-2') | ||
294 | expect(auth1).to.not.exist | ||
295 | }) | ||
296 | |||
261 | it('Should uninstall the plugin one and do not login Cyan', async function () { | 297 | it('Should uninstall the plugin one and do not login Cyan', async function () { |
262 | await uninstallPlugin({ | 298 | await uninstallPlugin({ |
263 | url: server.url, | 299 | url: server.url, |
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 6c10730aa..97df4c1fd 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts | |||
@@ -12,7 +12,7 @@ import { | |||
12 | updateMyUser, | 12 | updateMyUser, |
13 | userLogin, | 13 | userLogin, |
14 | wait, | 14 | wait, |
15 | login, refreshToken, getConfig | 15 | login, refreshToken, getConfig, updatePluginSettings |
16 | } from '../../../shared/extra-utils' | 16 | } from '../../../shared/extra-utils' |
17 | import { User, UserRole, ServerConfig } from '@shared/models' | 17 | import { User, UserRole, ServerConfig } from '@shared/models' |
18 | import { expect } from 'chai' | 18 | import { expect } from 'chai' |
@@ -179,6 +179,30 @@ describe('Test id and pass auth plugins', function () { | |||
179 | await waitUntilLog(server, 'valid email') | 179 | await waitUntilLog(server, 'valid email') |
180 | }) | 180 | }) |
181 | 181 | ||
182 | it('Should unregister spyro-auth and do not login existing Spyro', async function () { | ||
183 | await updatePluginSettings({ | ||
184 | url: server.url, | ||
185 | accessToken: server.accessToken, | ||
186 | npmName: 'peertube-plugin-test-id-pass-auth-one', | ||
187 | settings: { disableSpyro: true } | ||
188 | }) | ||
189 | |||
190 | await userLogin(server, { username: 'spyro', password: 'spyro password' }, 400) | ||
191 | await userLogin(server, { username: 'spyro', password: 'fake' }, 400) | ||
192 | }) | ||
193 | |||
194 | it('Should have disabled this auth', async function () { | ||
195 | const res = await getConfig(server.url) | ||
196 | |||
197 | const config: ServerConfig = res.body | ||
198 | |||
199 | const auths = config.plugin.registeredIdAndPassAuths | ||
200 | expect(auths).to.have.lengthOf(7) | ||
201 | |||
202 | const spyroAuth = auths.find(a => a.authName === 'spyro-auth') | ||
203 | expect(spyroAuth).to.not.exist | ||
204 | }) | ||
205 | |||
182 | it('Should uninstall the plugin one and do not login existing Crash', async function () { | 206 | it('Should uninstall the plugin one and do not login existing Crash', async function () { |
183 | await uninstallPlugin({ | 207 | await uninstallPlugin({ |
184 | url: server.url, | 208 | url: server.url, |