Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Small batch of fixes (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaperis authored Jun 14, 2023
2 parents 6515f82 + 7e84039 commit f1ee6af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
13 changes: 11 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,23 @@ func (c *Config) readConfig() error {
log.Printf("Setting log level to '%s'", stringLevel)
}

for _, s := range []string{"jwtIssuer", "JwtPrivateKey", "JwtSignatureAlg", "s3Inbox"} {
if viper.GetString("s3Inbox") == "" {
return fmt.Errorf("%s not set", "s3Inbox")
}

// no need to check the variables for JWT generation if we won't use it
if (cega.ID == "" && cega.Secret == "") && !c.ResignJwt {
return nil
}

for _, s := range []string{"jwtIssuer", "JwtPrivateKey", "JwtSignatureAlg"} {
if viper.GetString(s) == "" {
return fmt.Errorf("%s not set", s)
}
}

if _, err := os.Stat(c.JwtPrivateKey); errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("Missing private key file, reason: '%s'", err)
return fmt.Errorf("missing private key file, reason: '%s'", err.Error())
}

return nil
Expand Down
11 changes: 10 additions & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,14 @@ func (suite *ConfigTests) TestConfig() {

// re-read the config
_, err = NewConfig()
assert.ErrorContains(suite.T(), err, "Missing private key file")
assert.ErrorContains(suite.T(), err, "missing private key file")

// Repeat check with CEGA login and JWT resigning disabled
os.Setenv("CEGA_ID", "")
os.Setenv("CEGA_SECRET", "")
os.Setenv("RESIGNJWT", fmt.Sprintf("%t", false))

// re-read the config
_, err = NewConfig()
assert.NoError(suite.T(), err)
}
2 changes: 1 addition & 1 deletion dev-server/oidc/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const oidcConfig = {
revocation: true,
sessionManagement: false
},
format: {
formats: {
default: 'jwt',
AccessToken: 'jwt',
RefreshToken: 'jwt'
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (auth AuthHandler) getInboxConfig(ctx iris.Context, authType string) {
}
s3cfmap := s3conf.(map[string]string)
ctx.ResponseWriter().Header().Set("Content-Disposition", "attachment; filename=s3cmd.conf")
var s3c string
var s3c string = "[default]\n"

for k, v := range s3cfmap {
entry := fmt.Sprintf("%s = %s\n", k, v)
Expand Down Expand Up @@ -239,7 +239,7 @@ func (auth AuthHandler) elixirLogin(ctx iris.Context) *OIDCData {
code := ctx.Request().URL.Query().Get("code")
idStruct, err := authenticateWithOidc(auth.OAuth2Config, auth.OIDCProvider, code, auth.Config.Elixir.jwkURL)
if err != nil {
log.WithFields(log.Fields{"authType": "elixir"}).Errorf("Auhentication failed: %s", err)
log.WithFields(log.Fields{"authType": "elixir"}).Errorf("Authentication failed: %s", err)
_, err := ctx.Writef("Authentication failed. You may need to clear your session cookies and try again.")
if err != nil {
log.Error("Failed to write response: ", err)
Expand Down

0 comments on commit f1ee6af

Please sign in to comment.