Skip to content

Commit

Permalink
added test for info endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pahatz committed Dec 19, 2023
1 parent eb998d7 commit 671a73b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 0 additions & 4 deletions sda-auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ func (c *Config) readConfig() error {
log.Printf("Setting log level to '%s'", stringLevel)
}

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
Expand Down
5 changes: 5 additions & 0 deletions sda-auth/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ConfigTests struct {
InfoURL string
InfoText string
C4ghPubKeyFile string
PublicFile string
}

func TestConfigTestSuite(t *testing.T) {
Expand Down Expand Up @@ -90,6 +91,7 @@ func (suite *ConfigTests) SetupTest() {
suite.ResignJwt = true
suite.InfoURL = "https://test.info"
suite.InfoText = "About LEGA"
suite.PublicFile = "public.pem"

// Write config to temp config file
configYaml, err := yaml.Marshal(Config{
Expand All @@ -103,6 +105,7 @@ func (suite *ConfigTests) SetupTest() {
ResignJwt: suite.ResignJwt,
InfoURL: suite.InfoURL,
InfoText: suite.InfoText,
PublicFile: suite.PublicFile,
})
if err != nil {
log.Errorf("Error marshalling config yaml: %v", err)
Expand Down Expand Up @@ -187,6 +190,7 @@ func (suite *ConfigTests) TestConfig() {

os.Setenv("INFOTEXT", fmt.Sprintf("env_%v", suite.InfoText))
os.Setenv("INFOURL", fmt.Sprintf("env_%v", suite.InfoURL))
os.Setenv("PUBLICFILE", fmt.Sprintf("env_%v", suite.PublicFile))

// re-read the config
config, err = NewConfig()
Expand All @@ -213,6 +217,7 @@ func (suite *ConfigTests) TestConfig() {

assert.Equal(suite.T(), fmt.Sprintf("env_%v", suite.InfoText), config.InfoText, "Project info text misread from environment variable")
assert.Equal(suite.T(), fmt.Sprintf("env_%v", suite.InfoURL), config.InfoURL, "Project info text misread from environment variable")
assert.Equal(suite.T(), fmt.Sprintf("env_%v", suite.PublicFile), config.PublicFile, "Public file misread from environment variable")

// Check missing private key
os.Setenv("JWTPRIVATEKEY", "nonexistent-key-file")
Expand Down
2 changes: 1 addition & 1 deletion sda-auth/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func readPublicKeyFile(filename string) (key *[32]byte, err error) {

// getInfo returns information needed by the client to authenticate
func (auth AuthHandler) getInfo(ctx iris.Context) {
info := Info{ClientID: auth.OAuth2Config.ClientID, OidcURI: auth.Config.JwtIssuer, PublicKey: auth.pubKey, InboxURI: auth.Config.S3Inbox}
info := Info{ClientID: auth.OAuth2Config.ClientID, OidcURI: auth.Config.Elixir.Provider, PublicKey: auth.pubKey, InboxURI: auth.Config.S3Inbox}

err := ctx.JSON(info)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions sda-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func main() {
authHandler.pubKey = hex.EncodeToString(publicKey[:])
}

// Endpoint for client login info
if publicKey != nil {
app.Get("/info", authHandler.getInfo)
}
Expand Down

0 comments on commit 671a73b

Please sign in to comment.