Takwaiw/dendrite publickey (#2)

* Implementation of MSC 3782 Add publickey login as a new auth type.

Co-authored-by: Tak Wai Wong <takwaiw@gmail.com>
This commit is contained in:
Tak Wai Wong 2022-05-12 16:47:48 -07:00
parent 77e2c918fd
commit 8ab1737e7f
No known key found for this signature in database
GPG key ID: 222E4AF2AA1F467D
5 changed files with 9 additions and 14 deletions

View file

@ -244,7 +244,7 @@ func (u *UserInteractive) ResponseWithChallenge(sessionID string, response inter
// Verify returns an error/challenge response to send to the client, or nil if the user is authenticated.
// `bodyBytes` is the HTTP request body which must contain an `auth` key.
// Returns the login that was verified for additional checks if required.
func (u *UserInteractive) Verify(ctx context.Context, bodyBytes []byte, device *api.Device) (*Login, *util.JSONResponse) {
func (u *UserInteractive) Verify(ctx context.Context, bodyBytes []byte) (*Login, *util.JSONResponse) {
// TODO: rate limit
// "A client should first make a request with no auth parameter. The homeserver returns an HTTP 401 response, with a JSON body"

View file

@ -17,11 +17,6 @@ var (
serverName = gomatrixserverlib.ServerName("example.com")
// space separated localpart+password -> account
lookup = make(map[string]*api.Account)
device = &api.Device{
AccessToken: "flibble",
DisplayName: "My Device",
ID: "device_id_goes_here",
}
)
type fakeAccountDatabase struct {
@ -60,7 +55,7 @@ func setup() *UserInteractive {
func TestUserInteractiveChallenge(t *testing.T) {
uia := setup()
// no auth key results in a challenge
_, errRes := uia.Verify(ctx, []byte(`{}`), device)
_, errRes := uia.Verify(ctx, []byte(`{}`))
if errRes == nil {
t.Fatalf("Verify succeeded with {} but expected failure")
}
@ -100,7 +95,7 @@ func TestUserInteractivePasswordLogin(t *testing.T) {
}`),
}
for _, tc := range testCases {
_, errRes := uia.Verify(ctx, tc, device)
_, errRes := uia.Verify(ctx, tc)
if errRes != nil {
t.Errorf("Verify failed but expected success for request: %s - got %+v", string(tc), errRes)
}
@ -181,7 +176,7 @@ func TestUserInteractivePasswordBadLogin(t *testing.T) {
},
}
for _, tc := range testCases {
_, errRes := uia.Verify(ctx, tc.body, device)
_, errRes := uia.Verify(ctx, tc.body)
if errRes == nil {
t.Errorf("Verify succeeded but expected failure for request: %s", string(tc.body))
continue

View file

@ -28,7 +28,7 @@ func Deactivate(
}
}
login, errRes := userInteractiveAuth.Verify(ctx, bodyBytes, deviceAPI)
login, errRes := userInteractiveAuth.Verify(ctx, bodyBytes)
if errRes != nil {
return *errRes
}

View file

@ -198,7 +198,7 @@ func DeleteDeviceById(
sessionID = s
}
login, errRes := userInteractiveAuth.Verify(ctx, bodyBytes, device)
login, errRes := userInteractiveAuth.Verify(ctx, bodyBytes)
if errRes != nil {
switch data := errRes.JSON.(type) {
case auth.Challenge:

View file

@ -300,10 +300,10 @@ func Test_UserStatistics(t *testing.T) {
},
R30UsersV2: map[string]int64{
"ios": 0,
"android": 0,
"web": 0,
"android": 1,
"web": 1,
"electron": 0,
"all": 0,
"all": 2,
},
AllUsers: 6,
NonBridgedUsers: 5,