|
| 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 | +} |
0 commit comments