diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /packages/tests/src/external-plugins/auth-ldap.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'packages/tests/src/external-plugins/auth-ldap.ts')
-rw-r--r-- | packages/tests/src/external-plugins/auth-ldap.ts | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/packages/tests/src/external-plugins/auth-ldap.ts b/packages/tests/src/external-plugins/auth-ldap.ts new file mode 100644 index 000000000..ad058110c --- /dev/null +++ b/packages/tests/src/external-plugins/auth-ldap.ts | |||
@@ -0,0 +1,117 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@peertube/peertube-server-commands' | ||
5 | import { HttpStatusCode } from '@peertube/peertube-models' | ||
6 | |||
7 | describe('Official plugin auth-ldap', function () { | ||
8 | let server: PeerTubeServer | ||
9 | let accessToken: string | ||
10 | let userId: number | ||
11 | |||
12 | before(async function () { | ||
13 | this.timeout(30000) | ||
14 | |||
15 | server = await createSingleServer(1) | ||
16 | await setAccessTokensToServers([ server ]) | ||
17 | |||
18 | await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' }) | ||
19 | }) | ||
20 | |||
21 | it('Should not login with without LDAP settings', async function () { | ||
22 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
23 | }) | ||
24 | |||
25 | it('Should not login with bad LDAP settings', async function () { | ||
26 | await server.plugins.updateSettings({ | ||
27 | npmName: 'peertube-plugin-auth-ldap', | ||
28 | settings: { | ||
29 | 'bind-credentials': 'GoodNewsEveryone', | ||
30 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | ||
31 | 'insecure-tls': false, | ||
32 | 'mail-property': 'mail', | ||
33 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | ||
34 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | ||
35 | 'url': 'ldap://127.0.0.1:390', | ||
36 | 'username-property': 'uid' | ||
37 | } | ||
38 | }) | ||
39 | |||
40 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
41 | }) | ||
42 | |||
43 | it('Should not login with good LDAP settings but wrong username/password', async function () { | ||
44 | await server.plugins.updateSettings({ | ||
45 | npmName: 'peertube-plugin-auth-ldap', | ||
46 | settings: { | ||
47 | 'bind-credentials': 'GoodNewsEveryone', | ||
48 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | ||
49 | 'insecure-tls': false, | ||
50 | 'mail-property': 'mail', | ||
51 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | ||
52 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | ||
53 | 'url': 'ldap://127.0.0.1:10389', | ||
54 | 'username-property': 'uid' | ||
55 | } | ||
56 | }) | ||
57 | |||
58 | await server.login.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
59 | await server.login.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
60 | }) | ||
61 | |||
62 | it('Should login with the appropriate username/password', async function () { | ||
63 | accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' }) | ||
64 | }) | ||
65 | |||
66 | it('Should login with the appropriate email/password', async function () { | ||
67 | accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' }) | ||
68 | }) | ||
69 | |||
70 | it('Should login get my profile', async function () { | ||
71 | const body = await server.users.getMyInfo({ token: accessToken }) | ||
72 | expect(body.username).to.equal('fry') | ||
73 | expect(body.email).to.equal('fry@planetexpress.com') | ||
74 | |||
75 | userId = body.id | ||
76 | }) | ||
77 | |||
78 | it('Should upload a video', async function () { | ||
79 | await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } }) | ||
80 | }) | ||
81 | |||
82 | it('Should not be able to login if the user is banned', async function () { | ||
83 | await server.users.banUser({ userId }) | ||
84 | |||
85 | await server.login.login({ | ||
86 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | ||
87 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
88 | }) | ||
89 | }) | ||
90 | |||
91 | it('Should be able to login if the user is unbanned', async function () { | ||
92 | await server.users.unbanUser({ userId }) | ||
93 | |||
94 | await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } }) | ||
95 | }) | ||
96 | |||
97 | it('Should not be able to ask password reset', async function () { | ||
98 | await server.users.askResetPassword({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 }) | ||
99 | }) | ||
100 | |||
101 | it('Should not be able to ask email verification', async function () { | ||
102 | await server.users.askSendVerifyEmail({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 }) | ||
103 | }) | ||
104 | |||
105 | it('Should not login if the plugin is uninstalled', async function () { | ||
106 | await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' }) | ||
107 | |||
108 | await server.login.login({ | ||
109 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | ||
110 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
111 | }) | ||
112 | }) | ||
113 | |||
114 | after(async function () { | ||
115 | await cleanupTests([ server ]) | ||
116 | }) | ||
117 | }) | ||