Skip to content

Commit adae8c1

Browse files
meenal06kegsay
andauthored
feat: add change_password pushers test (#147)
* feat: add change_password pushers test: Signed-off-by: Meenal Trivedi <[email protected]> * fix Signed-off-by: Meenal Trivedi <[email protected]> * password fix Signed-off-by: Meenal Trivedi <[email protected]> * fix Signed-off-by: Meenal Trivedi <[email protected]> * fix Signed-off-by: Meenal Trivedi <[email protected]> * fix Signed-off-by: Meenal Trivedi <[email protected]> * fix Signed-off-by: Meenal Trivedi <[email protected]> * Update account_change_password_pushers_test.go * Update account_change_password_pushers_test.go * Update tests/account_change_password_pushers_test.go * Update tests/account_change_password_pushers_test.go Co-authored-by: kegsay <[email protected]>
1 parent fc048eb commit adae8c1

File tree

2 files changed

+103
-8
lines changed

2 files changed

+103
-8
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// +build !dendrite_blacklist
2+
3+
package tests
4+
5+
import (
6+
"testing"
7+
8+
"github.com/matrix-org/complement/internal/b"
9+
"github.com/matrix-org/complement/internal/client"
10+
"github.com/matrix-org/complement/internal/match"
11+
"github.com/matrix-org/complement/internal/must"
12+
13+
"github.com/tidwall/gjson"
14+
)
15+
16+
func TestChangePasswordPushers(t *testing.T) {
17+
deployment := Deploy(t, b.BlueprintAlice)
18+
defer deployment.Destroy(t)
19+
password1 := "superuser"
20+
password2 := "my_new_password"
21+
passwordClient := deployment.RegisterUser(t, "hs1", "test_change_password_pusher_user", password1)
22+
23+
// sytest: Pushers created with a different access token are deleted on password change
24+
t.Run("Pushers created with a different access token are deleted on password change", func(t *testing.T) {
25+
sessionOptional := createSession(t, deployment, passwordClient.UserID, password1)
26+
reqBody := client.WithJSONBody(t, map[string]interface{}{
27+
"data": map[string]interface{}{
28+
"url": "https://dummy.url/_matrix/push/v1/notify",
29+
},
30+
"profile_tag": "tag",
31+
"kind": "http",
32+
"app_id": "complement",
33+
"app_display_name": "complement_display_name",
34+
"device_display_name": "device_display_name",
35+
"pushkey": "a_push_key",
36+
"lang": "en",
37+
})
38+
39+
_ = sessionOptional.MustDoFunc(t, "POST", []string{"_matrix", "client", "r0", "pushers", "set"}, reqBody)
40+
41+
changePassword(t, passwordClient, password1, password2)
42+
43+
pushersSize := 0
44+
45+
res := passwordClient.DoFunc(t, "GET", []string{"_matrix", "client", "r0", "pushers"})
46+
must.MatchResponse(t, res, match.HTTPResponse{
47+
StatusCode: 200,
48+
JSON: []match.JSON{
49+
match.JSONArrayEach("pushers", func(val gjson.Result) error {
50+
pushersSize++
51+
return nil
52+
}),
53+
},
54+
})
55+
if pushersSize != 0 {
56+
t.Errorf("pushers size expected to be 0, found %d", pushersSize)
57+
}
58+
})
59+
60+
// sytest: Pushers created with a the same access token are not deleted on password change
61+
t.Run("Pushers created with a the same access token are not deleted on password change", func(t *testing.T) {
62+
reqBody := client.WithJSONBody(t, map[string]interface{}{
63+
"data": map[string]interface{}{
64+
"url": "https://dummy.url/_matrix/push/v1/notify",
65+
},
66+
"profile_tag": "tag",
67+
"kind": "http",
68+
"app_id": "complement",
69+
"app_display_name": "complement_display_name",
70+
"device_display_name": "device_display_name",
71+
"pushkey": "a_push_key",
72+
"lang": "en",
73+
})
74+
75+
_ = passwordClient.MustDoFunc(t, "POST", []string{"_matrix", "client", "r0", "pushers", "set"}, reqBody)
76+
77+
changePassword(t, passwordClient, password2, password1)
78+
79+
pushersSize := 0
80+
81+
res := passwordClient.DoFunc(t, "GET", []string{"_matrix", "client", "r0", "pushers"})
82+
must.MatchResponse(t, res, match.HTTPResponse{
83+
StatusCode: 200,
84+
JSON: []match.JSON{
85+
match.JSONArrayEach("pushers", func(val gjson.Result) error {
86+
pushersSize++
87+
return nil
88+
}),
89+
},
90+
})
91+
if pushersSize != 1 {
92+
t.Errorf("pushers size expected to be 1, found %d", pushersSize)
93+
}
94+
})
95+
}

tests/account_change_password_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ import (
1616
func TestChangePassword(t *testing.T) {
1717
deployment := Deploy(t, b.BlueprintAlice)
1818
defer deployment.Destroy(t)
19-
oldPassword := "superuser"
20-
newPassword := "my_new_password"
21-
passwordClient := deployment.RegisterUser(t, "hs1", "test_change_password_user", oldPassword)
19+
password1 := "superuser"
20+
password2 := "my_new_password"
21+
passwordClient := deployment.RegisterUser(t, "hs1", "test_change_password_user", password1)
2222
unauthedClient := deployment.Client(t, "hs1", "")
2323
sessionTest := createSession(t, deployment, "test_change_password_user", "superuser")
2424
// sytest: After changing password, can't log in with old password
2525
t.Run("After changing password, can't log in with old password", func(t *testing.T) {
2626

27-
changePassword(t, passwordClient, oldPassword, newPassword)
27+
changePassword(t, passwordClient, password1, password2)
2828

2929
reqBody := client.WithJSONBody(t, map[string]interface{}{
3030
"identifier": map[string]interface{}{
3131
"type": "m.id.user",
3232
"user": passwordClient.UserID,
3333
},
3434
"type": "m.login.password",
35-
"password": oldPassword,
35+
"password": password1,
3636
})
3737
res := unauthedClient.DoFunc(t, "POST", []string{"_matrix", "client", "r0", "login"}, reqBody)
3838
must.MatchResponse(t, res, match.HTTPResponse{
@@ -51,7 +51,7 @@ func TestChangePassword(t *testing.T) {
5151
"user": passwordClient.UserID,
5252
},
5353
"type": "m.login.password",
54-
"password": newPassword,
54+
"password": password2,
5555
})
5656
res := unauthedClient.DoFunc(t, "POST", []string{"_matrix", "client", "r0", "login"}, reqBody)
5757
must.MatchResponse(t, res, match.HTTPResponse{
@@ -78,12 +78,12 @@ func TestChangePassword(t *testing.T) {
7878

7979
// sytest: After changing password, different sessions can optionally be kept
8080
t.Run("After changing password, different sessions can optionally be kept", func(t *testing.T) {
81-
sessionOptional := createSession(t, deployment, "test_change_password_user", newPassword)
81+
sessionOptional := createSession(t, deployment, "test_change_password_user", password2)
8282
reqBody := client.WithJSONBody(t, map[string]interface{}{
8383
"auth": map[string]interface{}{
8484
"type": "m.login.password",
8585
"user": passwordClient.UserID,
86-
"password": newPassword,
86+
"password": password2,
8787
},
8888
"new_password": "new_optional_password",
8989
"logout_devices": false,

0 commit comments

Comments
 (0)