|
| 1 | +package tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/tidwall/gjson" |
| 8 | + |
| 9 | + "github.com/matrix-org/complement/internal/b" |
| 10 | + "github.com/matrix-org/complement/internal/match" |
| 11 | + "github.com/matrix-org/complement/internal/must" |
| 12 | +) |
| 13 | + |
| 14 | +func TestLogin(t *testing.T) { |
| 15 | + deployment := Deploy(t, "login", b.BlueprintAlice) |
| 16 | + defer deployment.Destroy(t) |
| 17 | + unauthedClient := deployment.Client(t, "hs1", "") |
| 18 | + t.Run("parallel", func(t *testing.T) { |
| 19 | + // sytest: POST /login can log in as a user |
| 20 | + t.Run("POST /login can login as user", func(t *testing.T) { |
| 21 | + t.Parallel() |
| 22 | + res := unauthedClient.MustDo(t, "POST", []string{"_matrix", "client", "r0", "register"}, json.RawMessage(`{ |
| 23 | + "auth": { |
| 24 | + "type": "m.login.dummy" |
| 25 | + }, |
| 26 | + "username": "post-login-user", |
| 27 | + "password": "superuser" |
| 28 | + }`)) |
| 29 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 30 | + JSON: []match.JSON{ |
| 31 | + match.JSONKeyTypeEqual("access_token", gjson.String), |
| 32 | + match.JSONKeyTypeEqual("user_id", gjson.String), |
| 33 | + }, |
| 34 | + }) |
| 35 | + //body, _ := ioutil.ReadAll(res.Body) |
| 36 | + //userId := gjson.Get(string(body), "user_id") |
| 37 | + res = unauthedClient.MustDo(t, "POST", []string{"_matrix", "client", "r0", "login"}, json.RawMessage(`{ |
| 38 | + "type": "m.login.password", |
| 39 | + "identifier": { |
| 40 | + "type": "m.id.user", |
| 41 | + "user": "post-login-user" |
| 42 | + }, |
| 43 | + "password": "superuser" |
| 44 | + }`)) |
| 45 | + |
| 46 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 47 | + JSON: []match.JSON{ |
| 48 | + match.JSONKeyTypeEqual("access_token", gjson.String), |
| 49 | + match.JSONKeyEqual("home_server", "hs1"), |
| 50 | + }, |
| 51 | + }) |
| 52 | + }) |
| 53 | + }) |
| 54 | +} |
0 commit comments