MCPcopy Create free account
hub / github.com/daodst/chat / TestBadLoginFromJSONReader

Function TestBadLoginFromJSONReader

clientapi/auth/login_test.go:99–159  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func TestBadLoginFromJSONReader(t *testing.T) {
100 ctx := context.Background()
101
102 tsts := []struct {
103 Name string
104 Body string
105
106 WantErrCode string
107 }{
108 {Name: "empty", WantErrCode: "M_BAD_JSON"},
109 {
110 Name: "badUnmarshal",
111 Body: `badsyntaxJSON`,
112 WantErrCode: "M_BAD_JSON",
113 },
114 {
115 Name: "badPassword",
116 Body: `{
117 "type": "m.login.password",
118 "identifier": { "type": "m.id.user", "user": "alice" },
119 "password": "invalidpassword",
120 "device_id": "adevice"
121 }`,
122 WantErrCode: "M_FORBIDDEN",
123 },
124 {
125 Name: "badToken",
126 Body: `{
127 "type": "m.login.token",
128 "token": "invalidtoken",
129 "device_id": "adevice"
130 }`,
131 WantErrCode: "M_FORBIDDEN",
132 },
133 {
134 Name: "badType",
135 Body: `{
136 "type": "m.login.invalid",
137 "device_id": "adevice"
138 }`,
139 WantErrCode: "M_INVALID_ARGUMENT_VALUE",
140 },
141 }
142 for _, tst := range tsts {
143 t.Run(tst.Name, func(t *testing.T) {
144 var userAPI fakeUserInternalAPI
145 cfg := &config.ClientAPI{
146 Matrix: &config.Global{
147 ServerName: serverName,
148 },
149 }
150 _, cleanup, errRes := LoginFromJSONReader(ctx, strings.NewReader(tst.Body), &userAPI, &userAPI, cfg)
151 if errRes == nil {
152 cleanup(ctx, nil)
153 t.Fatalf("LoginFromJSONReader err: got %+v, want code %q", errRes, tst.WantErrCode)
154 } else if merr, ok := errRes.JSON.(*jsonerror.MatrixError); ok && merr.ErrCode != tst.WantErrCode {
155 t.Fatalf("LoginFromJSONReader err: got %+v, want code %q", errRes, tst.WantErrCode)
156 }

Callers

nothing calls this directly

Calls 3

LoginFromJSONReaderFunction · 0.85
cleanupFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected