resolve some comments

This commit is contained in:
Samir Patel 2021-12-19 23:33:44 -06:00
parent 7ce07d4e4a
commit 0d52a952e0
4 changed files with 16 additions and 15 deletions

View file

@ -34,7 +34,7 @@ func NewAuth(logger logger.Logger, url string, scopes []string, authUrl, tokenUr
auth := &Auth{
logger: logger,
cookieName: "molecula-chip",
refreshWithin: time.Second * time.Duration(15),
refreshWithin: time.Minute * time.Duration(15),
groupEndpoint: groupEndpoint,
logoutEndpoint: "https://login.microsoftonline.com/common/oauth2/v2.0/logout",
fbURL: url,
@ -49,22 +49,17 @@ func NewAuth(logger logger.Logger, url string, scopes []string, authUrl, tokenUr
},
},
}
data, err := decodeHex(hashKey)
if err != nil {
var err error
if auth.hashKey, err = decodeHex(hashKey); err != nil {
return nil, errors.Wrap(err, "decoding hash key")
}
auth.hashKey = data
data, err = decodeHex(blockKey)
if err != nil {
if auth.blockKey, err = decodeHex(blockKey); err != nil {
return nil, errors.Wrap(err, "decoding block key")
}
auth.blockKey = data
auth.secure = securecookie.New(auth.hashKey, auth.blockKey)
auth.logger.Infof("AUTH: %+v", auth)
return auth, nil
}

View file

@ -99,12 +99,12 @@ func TestAuth(t *testing.T) {
// })
t.Run("Logout", func(t *testing.T) {
r := httptest.NewRequest(gohttp.MethodGet, "/login", nil)
r := httptest.NewRequest(gohttp.MethodGet, "/logout", nil)
w := httptest.NewRecorder()
a.Logout(w, r)
})
t.Run("Authenticate", func(t *testing.T) {
r := httptest.NewRequest(gohttp.MethodGet, "/login", nil)
r := httptest.NewRequest(gohttp.MethodGet, "/authenticate", nil)
w := httptest.NewRecorder()
a.Authenticate(w, r)
})
@ -114,7 +114,7 @@ func TestAuth(t *testing.T) {
// a.Redirect(w, r)
// })
t.Run("GetUserInfo", func(t *testing.T) {
r := httptest.NewRequest(gohttp.MethodGet, "/login", nil)
r := httptest.NewRequest(gohttp.MethodGet, "/userinfo", nil)
a.GetUserInfo(r)
})

View file

@ -363,7 +363,7 @@ func (h *Handler) collectStats(next http.Handler) http.Handler {
// latticeRoutes lists the frontend routes that do not directly correspond to
// backend routes, and require special handling.
var latticeRoutes = []string{"/tables", "/query", "/querybuilder", "/login"} // TODO somehow pull this from some metadata in the lattice directory
var latticeRoutes = []string{"/tables", "/query", "/querybuilder", "/signin"} // TODO somehow pull this from some metadata in the lattice directory
// newRouter creates a new mux http router.
func newRouter(handler *Handler) http.Handler {
@ -458,7 +458,7 @@ func newRouter(handler *Handler) http.Handler {
router.HandleFunc("/cpu-profile/stop", handler.handleCPUProfileStop).Methods("GET").Name("CPUProfileStop")
router.HandleFunc("/login", handler.handleLogin).Methods("GET").Name("Login")
router.HandleFunc("/logout", handler.handleLogout).Methods("GET").Name("Login")
router.HandleFunc("/logout", handler.handleLogout).Methods("GET").Name("Logout")
router.HandleFunc("/redirect", handler.handleRedirect).Methods("GET").Name("Redirect")
router.HandleFunc("/auth", handler.handleCheckAuthentication).Methods("GET").Name("CheckAuthentication")
router.HandleFunc("/userinfo", handler.handleUserInfo).Methods("GET").Name("UserInfo")

View file

@ -631,6 +631,12 @@ func (c *Config) ValidateAuth() ([]error, error) {
continue
}
if name == "HashKey" || name == "BlockKey" {
if len(value) != 32 {
errors = append(errors, fmt.Errorf("invalid key length for %s", name))
}
}
if strings.Contains(name, "URL") {
_, err := url.ParseRequestURI(value)
if err != nil {
@ -640,7 +646,7 @@ func (c *Config) ValidateAuth() ([]error, error) {
}
}
if len(c.Auth.Scopes) == 0 {
errors = append(errors, fmt.Errorf("must provide scope for authentication with IdP"))
errors = append(errors, fmt.Errorf("must provide scope for authentication with IdP - for access and refresh token"))
}
if len(errors) > 0 {
return errors, fmt.Errorf("there were errors validating config")