Skip to content

Commit

Permalink
[extension/oauth2clientauth] Remove duplicate validation logic (open-…
Browse files Browse the repository at this point in the history
…telemetry#30469)

**Description:**
remove the duplicate validation logic, use config.Validate instead.
  • Loading branch information
atoulme authored and cparkins committed Feb 1, 2024
1 parent 66676fd commit 32dc08d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 67 deletions.
10 changes: 0 additions & 10 deletions extension/oauth2clientauthextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ var _ oauth2.TokenSource = (*errorWrappingTokenSource)(nil)
var errFailedToGetSecurityToken = fmt.Errorf("failed to get security token from token endpoint")

func newClientAuthenticator(cfg *Config, logger *zap.Logger) (*clientAuthenticator, error) {
if cfg.ClientID == "" && cfg.ClientIDFile == "" {
return nil, errNoClientIDProvided
}
if cfg.ClientSecret == "" && cfg.ClientSecretFile == "" {
return nil, errNoClientSecretProvided
}
if cfg.TokenURL == "" {
return nil, errNoTokenURLProvided
}

transport := http.DefaultTransport.(*http.Transport).Clone()

tlsCfg, err := cfg.TLSSetting.LoadTLSConfig()
Expand Down
48 changes: 0 additions & 48 deletions extension/oauth2clientauthextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,6 @@ func TestOAuthClientSettings(t *testing.T) {
shouldError: true,
expectedError: "failed to load TLS config: failed to load TLS cert and key",
},
{
name: "missing_client_id",
settings: &Config{
ClientSecret: "testsecret",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
expectedError: errNoClientIDProvided.Error(),
},
{
name: "missing_client_secret",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
expectedError: errNoClientSecretProvided.Error(),
},
{
name: "missing_token_url",
settings: &Config{
ClientID: "testclientid",
ClientSecret: "testsecret",
Scopes: []string{"resource.read"},
},
shouldError: true,
expectedError: errNoTokenURLProvided.Error(),
},
}

for _, test := range tests {
Expand Down Expand Up @@ -251,15 +221,6 @@ func TestRoundTripper(t *testing.T) {
},
shouldError: false,
},
{
name: "invalid_client_settings_should_error",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
},
}

testString := "TestString"
Expand Down Expand Up @@ -308,15 +269,6 @@ func TestOAuth2PerRPCCredentials(t *testing.T) {
},
shouldError: false,
},
{
name: "invalid_client_settings_should_error",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
},
}

for _, testcase := range tests {
Expand Down
9 changes: 0 additions & 9 deletions extension/oauth2clientauthextension/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ func TestCreateExtension(t *testing.T) {
},
shouldError: false,
},
{
name: "invalid_client_settings_should_error",
settings: &Config{
ClientID: "testclientid",
TokenURL: "https://example.com/v1/token",
Scopes: []string{"resource.read"},
},
shouldError: true,
},
}

for _, testcase := range tests {
Expand Down

0 comments on commit 32dc08d

Please sign in to comment.