diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/config.ts | 23 | ||||
-rw-r--r-- | server/tests/api/check-params/user-notifications.ts | 3 | ||||
-rw-r--r-- | server/tests/api/notifications/user-notifications.ts | 40 | ||||
-rw-r--r-- | server/tests/api/server/auto-follows.ts | 148 | ||||
-rw-r--r-- | server/tests/api/server/config.ts | 19 | ||||
-rw-r--r-- | server/tests/api/server/index.ts | 1 |
6 files changed, 227 insertions, 7 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 7773ae1e7..1221735c5 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -5,8 +5,16 @@ import 'mocha' | |||
5 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' |
6 | 6 | ||
7 | import { | 7 | import { |
8 | createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, flushAndRunServer, ServerInfo, | 8 | cleanupTests, |
9 | setAccessTokensToServers, userLogin, immutableAssign, cleanupTests | 9 | createUser, |
10 | flushAndRunServer, | ||
11 | immutableAssign, | ||
12 | makeDeleteRequest, | ||
13 | makeGetRequest, | ||
14 | makePutBodyRequest, | ||
15 | ServerInfo, | ||
16 | setAccessTokensToServers, | ||
17 | userLogin | ||
10 | } from '../../../../shared/extra-utils' | 18 | } from '../../../../shared/extra-utils' |
11 | 19 | ||
12 | describe('Test config API validators', function () { | 20 | describe('Test config API validators', function () { |
@@ -98,6 +106,17 @@ describe('Test config API validators', function () { | |||
98 | enabled: false, | 106 | enabled: false, |
99 | manualApproval: true | 107 | manualApproval: true |
100 | } | 108 | } |
109 | }, | ||
110 | followings: { | ||
111 | instance: { | ||
112 | autoFollowBack: { | ||
113 | enabled: true | ||
114 | }, | ||
115 | autoFollowIndex: { | ||
116 | enabled: true, | ||
117 | indexUrl: 'https://index.example.com' | ||
118 | } | ||
119 | } | ||
101 | } | 120 | } |
102 | } | 121 | } |
103 | 122 | ||
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 14ee20d45..3b06be7ef 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts | |||
@@ -172,7 +172,8 @@ describe('Test user notifications API validators', function () { | |||
172 | commentMention: UserNotificationSettingValue.WEB, | 172 | commentMention: UserNotificationSettingValue.WEB, |
173 | newFollow: UserNotificationSettingValue.WEB, | 173 | newFollow: UserNotificationSettingValue.WEB, |
174 | newUserRegistration: UserNotificationSettingValue.WEB, | 174 | newUserRegistration: UserNotificationSettingValue.WEB, |
175 | newInstanceFollower: UserNotificationSettingValue.WEB | 175 | newInstanceFollower: UserNotificationSettingValue.WEB, |
176 | autoInstanceFollowing: UserNotificationSettingValue.WEB | ||
176 | } | 177 | } |
177 | 178 | ||
178 | it('Should fail with missing fields', async function () { | 179 | it('Should fail with missing fields', async function () { |
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 6fa630562..62b797b47 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts | |||
@@ -16,8 +16,8 @@ import { | |||
16 | immutableAssign, | 16 | immutableAssign, |
17 | registerUser, | 17 | registerUser, |
18 | removeVideoFromBlacklist, | 18 | removeVideoFromBlacklist, |
19 | reportVideoAbuse, | 19 | reportVideoAbuse, unfollow, |
20 | updateCustomConfig, | 20 | updateCustomConfig, updateCustomSubConfig, |
21 | updateMyUser, | 21 | updateMyUser, |
22 | updateVideo, | 22 | updateVideo, |
23 | updateVideoChannel, | 23 | updateVideoChannel, |
@@ -45,7 +45,8 @@ import { | |||
45 | getUserNotifications, | 45 | getUserNotifications, |
46 | markAsReadAllNotifications, | 46 | markAsReadAllNotifications, |
47 | markAsReadNotifications, | 47 | markAsReadNotifications, |
48 | updateMyNotificationSettings | 48 | updateMyNotificationSettings, |
49 | checkAutoInstanceFollowing | ||
49 | } from '../../../../shared/extra-utils/users/user-notifications' | 50 | } from '../../../../shared/extra-utils/users/user-notifications' |
50 | import { | 51 | import { |
51 | User, | 52 | User, |
@@ -108,7 +109,8 @@ describe('Test users notifications', function () { | |||
108 | commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 109 | commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
109 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 110 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
110 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 111 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
111 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | 112 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
113 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
112 | } | 114 | } |
113 | 115 | ||
114 | before(async function () { | 116 | before(async function () { |
@@ -897,6 +899,36 @@ describe('Test users notifications', function () { | |||
897 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 899 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } |
898 | await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') | 900 | await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') |
899 | }) | 901 | }) |
902 | |||
903 | it('Should send a notification on auto follow back', async function () { | ||
904 | this.timeout(40000) | ||
905 | |||
906 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | ||
907 | await waitJobs(servers) | ||
908 | |||
909 | const config = { | ||
910 | followings: { | ||
911 | instance: { | ||
912 | autoFollowBack: { enabled: true } | ||
913 | } | ||
914 | } | ||
915 | } | ||
916 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
917 | |||
918 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | ||
919 | |||
920 | await waitJobs(servers) | ||
921 | |||
922 | const followerHost = servers[0].host | ||
923 | const followingHost = servers[2].host | ||
924 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | ||
925 | |||
926 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
927 | await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') | ||
928 | |||
929 | config.followings.instance.autoFollowBack.enabled = false | ||
930 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
931 | }) | ||
900 | }) | 932 | }) |
901 | 933 | ||
902 | describe('New actor follow', function () { | 934 | describe('New actor follow', function () { |
diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts new file mode 100644 index 000000000..32ad259c9 --- /dev/null +++ b/server/tests/api/server/auto-follows.ts | |||
@@ -0,0 +1,148 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { | ||
6 | acceptFollower, | ||
7 | cleanupTests, | ||
8 | flushAndRunMultipleServers, | ||
9 | ServerInfo, | ||
10 | setAccessTokensToServers, | ||
11 | unfollow, | ||
12 | updateCustomSubConfig | ||
13 | } from '../../../../shared/extra-utils/index' | ||
14 | import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort } from '../../../../shared/extra-utils/server/follows' | ||
15 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
16 | import { ActorFollow } from '../../../../shared/models/actors' | ||
17 | |||
18 | const expect = chai.expect | ||
19 | |||
20 | async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: boolean) { | ||
21 | { | ||
22 | const res = await getFollowersListPaginationAndSort(following.url, 0, 5, '-createdAt') | ||
23 | const follows = res.body.data as ActorFollow[] | ||
24 | |||
25 | if (exists === true) { | ||
26 | expect(res.body.total).to.equal(1) | ||
27 | |||
28 | expect(follows[ 0 ].follower.host).to.equal(follower.host) | ||
29 | expect(follows[ 0 ].state).to.equal('accepted') | ||
30 | } else { | ||
31 | expect(follows.filter(f => f.state === 'accepted')).to.have.lengthOf(0) | ||
32 | } | ||
33 | } | ||
34 | |||
35 | { | ||
36 | const res = await getFollowingListPaginationAndSort(follower.url, 0, 5, '-createdAt') | ||
37 | const follows = res.body.data as ActorFollow[] | ||
38 | |||
39 | if (exists === true) { | ||
40 | expect(res.body.total).to.equal(1) | ||
41 | |||
42 | expect(follows[ 0 ].following.host).to.equal(following.host) | ||
43 | expect(follows[ 0 ].state).to.equal('accepted') | ||
44 | } else { | ||
45 | expect(follows.filter(f => f.state === 'accepted')).to.have.lengthOf(0) | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
50 | async function server1Follows2 (servers: ServerInfo[]) { | ||
51 | await follow(servers[0].url, [ servers[1].host ], servers[0].accessToken) | ||
52 | |||
53 | await waitJobs(servers) | ||
54 | } | ||
55 | |||
56 | async function resetFollows (servers: ServerInfo[]) { | ||
57 | try { | ||
58 | await unfollow(servers[ 0 ].url, servers[ 0 ].accessToken, servers[ 1 ]) | ||
59 | await unfollow(servers[ 1 ].url, servers[ 1 ].accessToken, servers[ 0 ]) | ||
60 | } catch { /* empty */ } | ||
61 | |||
62 | await waitJobs(servers) | ||
63 | |||
64 | await checkFollow(servers[0], servers[1], false) | ||
65 | await checkFollow(servers[1], servers[0], false) | ||
66 | } | ||
67 | |||
68 | describe('Test auto follows', function () { | ||
69 | let servers: ServerInfo[] = [] | ||
70 | |||
71 | before(async function () { | ||
72 | this.timeout(30000) | ||
73 | |||
74 | servers = await flushAndRunMultipleServers(2) | ||
75 | |||
76 | // Get the access tokens | ||
77 | await setAccessTokensToServers(servers) | ||
78 | }) | ||
79 | |||
80 | describe('Auto follow back', function () { | ||
81 | |||
82 | it('Should not auto follow back if the option is not enabled', async function () { | ||
83 | this.timeout(15000) | ||
84 | |||
85 | await server1Follows2(servers) | ||
86 | |||
87 | await checkFollow(servers[0], servers[1], true) | ||
88 | await checkFollow(servers[1], servers[0], false) | ||
89 | |||
90 | await resetFollows(servers) | ||
91 | }) | ||
92 | |||
93 | it('Should auto follow back on auto accept if the option is enabled', async function () { | ||
94 | this.timeout(15000) | ||
95 | |||
96 | const config = { | ||
97 | followings: { | ||
98 | instance: { | ||
99 | autoFollowBack: { enabled: true } | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) | ||
104 | |||
105 | await server1Follows2(servers) | ||
106 | |||
107 | await checkFollow(servers[0], servers[1], true) | ||
108 | await checkFollow(servers[1], servers[0], true) | ||
109 | |||
110 | await resetFollows(servers) | ||
111 | }) | ||
112 | |||
113 | it('Should wait the acceptation before auto follow back', async function () { | ||
114 | this.timeout(30000) | ||
115 | |||
116 | const config = { | ||
117 | followings: { | ||
118 | instance: { | ||
119 | autoFollowBack: { enabled: true } | ||
120 | } | ||
121 | }, | ||
122 | followers: { | ||
123 | instance: { | ||
124 | manualApproval: true | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) | ||
129 | |||
130 | await server1Follows2(servers) | ||
131 | |||
132 | await checkFollow(servers[0], servers[1], false) | ||
133 | await checkFollow(servers[1], servers[0], false) | ||
134 | |||
135 | await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@' + servers[0].host) | ||
136 | await waitJobs(servers) | ||
137 | |||
138 | await checkFollow(servers[0], servers[1], true) | ||
139 | await checkFollow(servers[1], servers[0], true) | ||
140 | |||
141 | await resetFollows(servers) | ||
142 | }) | ||
143 | }) | ||
144 | |||
145 | after(async function () { | ||
146 | await cleanupTests(servers) | ||
147 | }) | ||
148 | }) | ||
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 78fdc9cc0..b2f1933d1 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -68,6 +68,10 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) { | |||
68 | 68 | ||
69 | expect(data.followers.instance.enabled).to.be.true | 69 | expect(data.followers.instance.enabled).to.be.true |
70 | expect(data.followers.instance.manualApproval).to.be.false | 70 | expect(data.followers.instance.manualApproval).to.be.false |
71 | |||
72 | expect(data.followings.instance.autoFollowBack.enabled).to.be.false | ||
73 | expect(data.followings.instance.autoFollowIndex.enabled).to.be.false | ||
74 | expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org') | ||
71 | } | 75 | } |
72 | 76 | ||
73 | function checkUpdatedConfig (data: CustomConfig) { | 77 | function checkUpdatedConfig (data: CustomConfig) { |
@@ -119,6 +123,10 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
119 | 123 | ||
120 | expect(data.followers.instance.enabled).to.be.false | 124 | expect(data.followers.instance.enabled).to.be.false |
121 | expect(data.followers.instance.manualApproval).to.be.true | 125 | expect(data.followers.instance.manualApproval).to.be.true |
126 | |||
127 | expect(data.followings.instance.autoFollowBack.enabled).to.be.true | ||
128 | expect(data.followings.instance.autoFollowIndex.enabled).to.be.true | ||
129 | expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com') | ||
122 | } | 130 | } |
123 | 131 | ||
124 | describe('Test config', function () { | 132 | describe('Test config', function () { |
@@ -261,6 +269,17 @@ describe('Test config', function () { | |||
261 | enabled: false, | 269 | enabled: false, |
262 | manualApproval: true | 270 | manualApproval: true |
263 | } | 271 | } |
272 | }, | ||
273 | followings: { | ||
274 | instance: { | ||
275 | autoFollowBack: { | ||
276 | enabled: true | ||
277 | }, | ||
278 | autoFollowIndex: { | ||
279 | enabled: true, | ||
280 | indexUrl: 'https://updated.example.com' | ||
281 | } | ||
282 | } | ||
264 | } | 283 | } |
265 | } | 284 | } |
266 | await updateCustomConfig(server.url, server.accessToken, newCustomConfig) | 285 | await updateCustomConfig(server.url, server.accessToken, newCustomConfig) |
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index 3daeeb49a..08205b2c8 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import './auto-follows' | ||
1 | import './config' | 2 | import './config' |
2 | import './contact-form' | 3 | import './contact-form' |
3 | import './email' | 4 | import './email' |