-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(oauth login browser): implements /auth/login As discussed on call, we integration test only the handler and avoid mocks to see the behaviour is as expected. This is also true when we come to implements the callback logic and are required to start the flow from scratch. The current test in auth_handler_test will be updated to cover the entire flow when implementing /callback. As for the state todo, I need to see how to track the state between requests and the TODO will be completed in the /callback PR. 6646 * pr comments * pr comments * feat(browser flow for dashboard): implements browser flow (without sessions) This PR includes a small refactor to the admin device flow, such that it can share the same identity update logic within the browser flow. * feat(validation in auth handler): validates params given are correct and auth svc not nill * Fix tests * pr comments * additional failure tests * test fix * Update refresh token
- Loading branch information
Showing
16 changed files
with
322 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,23 +14,31 @@ import ( | |
"time" | ||
|
||
"github.com/canonical/jimm/internal/auth" | ||
"github.com/canonical/jimm/internal/db" | ||
"github.com/canonical/jimm/internal/dbmodel" | ||
"github.com/canonical/jimm/internal/jimmtest" | ||
"github.com/coreos/go-oidc/v3/oidc" | ||
qt "github.com/frankban/quicktest" | ||
) | ||
|
||
func setupTestAuthSvc(ctx context.Context, c *qt.C, expiry time.Duration) *auth.AuthenticationService { | ||
func setupTestAuthSvc(ctx context.Context, c *qt.C, expiry time.Duration) (*auth.AuthenticationService, *db.Database) { | ||
db := &db.Database{ | ||
DB: jimmtest.PostgresDB(c, func() time.Time { return time.Now() }), | ||
} | ||
c.Assert(db.Migrate(ctx, false), qt.IsNil) | ||
|
||
authSvc, err := auth.NewAuthenticationService(ctx, auth.AuthenticationServiceParams{ | ||
IssuerURL: "http://localhost:8082/realms/jimm", | ||
ClientID: "jimm-device", | ||
ClientSecret: "SwjDofnbDzJDm9iyfUhEp67FfUFMY8L4", | ||
Scopes: []string{oidc.ScopeOpenID, "profile", "email"}, | ||
SessionTokenExpiry: expiry, | ||
RedirectURL: "http://localhost:8080/auth/callback", | ||
Store: db, | ||
}) | ||
c.Assert(err, qt.IsNil) | ||
|
||
return authSvc | ||
return authSvc, db | ||
} | ||
|
||
// This test requires the local docker compose to be running and keycloak | ||
|
@@ -41,7 +49,7 @@ func TestAuthCodeURL(t *testing.T) { | |
c := qt.New(t) | ||
ctx := context.Background() | ||
|
||
authSvc := setupTestAuthSvc(ctx, c, time.Hour) | ||
authSvc, _ := setupTestAuthSvc(ctx, c, time.Hour) | ||
|
||
url := authSvc.AuthCodeURL() | ||
c.Assert( | ||
|
@@ -67,7 +75,7 @@ func TestDevice(t *testing.T) { | |
|
||
ctx := context.Background() | ||
|
||
authSvc := setupTestAuthSvc(ctx, c, time.Hour) | ||
authSvc, db := setupTestAuthSvc(ctx, c, time.Hour) | ||
|
||
res, err := authSvc.Device(ctx) | ||
c.Assert(err, qt.IsNil) | ||
|
@@ -138,6 +146,17 @@ func TestDevice(t *testing.T) { | |
email, err := authSvc.Email(idToken) | ||
c.Assert(err, qt.IsNil) | ||
c.Assert(email, qt.Equals, u.Email) | ||
|
||
// Update the identity | ||
err = authSvc.UpdateIdentity(ctx, email, token) | ||
c.Assert(err, qt.IsNil) | ||
|
||
updatedUser := &dbmodel.Identity{ | ||
Name: u.Email, | ||
} | ||
c.Assert(db.GetIdentity(ctx, updatedUser), qt.IsNil) | ||
c.Assert(updatedUser.AccessToken, qt.Not(qt.Equals), "") | ||
c.Assert(updatedUser.RefreshToken, qt.Not(qt.Equals), "") | ||
} | ||
|
||
// TestSessionTokens tests both the minting and validation of JIMM | ||
|
@@ -147,7 +166,7 @@ func TestSessionTokens(t *testing.T) { | |
|
||
ctx := context.Background() | ||
|
||
authSvc := setupTestAuthSvc(ctx, c, time.Hour) | ||
authSvc, _ := setupTestAuthSvc(ctx, c, time.Hour) | ||
|
||
secretKey := "secret-key" | ||
token, err := authSvc.MintSessionToken("[email protected]", secretKey) | ||
|
@@ -164,7 +183,7 @@ func TestSessionTokenRejectsWrongSecretKey(t *testing.T) { | |
|
||
ctx := context.Background() | ||
|
||
authSvc := setupTestAuthSvc(ctx, c, time.Hour) | ||
authSvc, _ := setupTestAuthSvc(ctx, c, time.Hour) | ||
|
||
secretKey := "secret-key" | ||
token, err := authSvc.MintSessionToken("[email protected]", secretKey) | ||
|
@@ -181,7 +200,7 @@ func TestSessionTokenRejectsExpiredToken(t *testing.T) { | |
ctx := context.Background() | ||
|
||
noDuration := time.Duration(0) | ||
authSvc := setupTestAuthSvc(ctx, c, noDuration) | ||
authSvc, _ := setupTestAuthSvc(ctx, c, noDuration) | ||
|
||
secretKey := "secret-key" | ||
token, err := authSvc.MintSessionToken("[email protected]", secretKey) | ||
|
@@ -197,7 +216,7 @@ func TestSessionTokenValidatesEmail(t *testing.T) { | |
|
||
ctx := context.Background() | ||
|
||
authSvc := setupTestAuthSvc(ctx, c, time.Hour) | ||
authSvc, _ := setupTestAuthSvc(ctx, c, time.Hour) | ||
|
||
secretKey := "secret-key" | ||
token, err := authSvc.MintSessionToken("", secretKey) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.