Skip to content

Commit

Permalink
Merge branch 'master' into pv-532-log
Browse files Browse the repository at this point in the history
  • Loading branch information
filariow authored Jul 31, 2024
2 parents e1c5c9b + 0eb4c1f commit b6363f2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func (r RegistrationServiceConfig) Print() {
logger.Info("Registration Service Configuration", "config", r.cfg.Host.RegistrationService)
}

func (r RegistrationServiceConfig) PublicViewerEnabled() bool {
return r.cfg.Host.PublicViewerConfig != nil && r.cfg.Host.PublicViewerConfig.Enabled
}

func (r RegistrationServiceConfig) Environment() string {
return commonconfig.GetString(r.cfg.Host.RegistrationService.Environment, prodEnvironment)
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package configuration_test
import (
"testing"

"github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/test"
commonconfig "github.com/codeready-toolchain/toolchain-common/pkg/configuration"
Expand Down Expand Up @@ -68,6 +69,7 @@ func TestRegistrationService(t *testing.T) {
assert.InDelta(t, float32(0), regServiceCfg.Verification().CaptchaRequiredScore(), 0.01)
assert.True(t, regServiceCfg.Verification().CaptchaAllowLowScoreReactivation())
assert.Empty(t, regServiceCfg.Verification().CaptchaServiceAccountFileContents())
assert.False(t, regServiceCfg.PublicViewerEnabled())
})
t.Run("non-default", func(t *testing.T) {
// given
Expand Down Expand Up @@ -151,5 +153,42 @@ func TestRegistrationService(t *testing.T) {
assert.InDelta(t, float32(0.5), regServiceCfg.Verification().CaptchaRequiredScore(), 0.01)
assert.False(t, regServiceCfg.Verification().CaptchaAllowLowScoreReactivation())
assert.Equal(t, "example-content", regServiceCfg.Verification().CaptchaServiceAccountFileContents())
assert.False(t, regServiceCfg.PublicViewerEnabled())
})
}

func TestPublicViewerConfiguration(t *testing.T) {
tt := map[string]struct {
name string
expectedValue bool
publicViewerConfig *v1alpha1.PublicViewerConfiguration
}{
"public-viewer is explicitly enabled": {
expectedValue: true,
publicViewerConfig: &v1alpha1.PublicViewerConfiguration{Enabled: true},
},
"public-viewer is explicitly disabled": {
expectedValue: false,
publicViewerConfig: &v1alpha1.PublicViewerConfiguration{Enabled: false},
},
"public-viewer config not set, assume disabled": {
expectedValue: false,
publicViewerConfig: nil,
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
// given
cfg := commonconfig.NewToolchainConfigObjWithReset(t)
cfg.Spec.Host.PublicViewerConfig = tc.publicViewerConfig
secrets := make(map[string]map[string]string)

// when
regServiceCfg := configuration.NewRegistrationServiceConfig(cfg, secrets)

// then
assert.Equal(t, tc.expectedValue, regServiceCfg.PublicViewerEnabled())
})
}
}

0 comments on commit b6363f2

Please sign in to comment.