Skip to content

Commit 3cd77d8

Browse files
authored
add provider config validity checks (#44)
if provider is configured with empty secrets, it may error in an unrelated area while performing requests. this PR adds an additional checks for the config to be correct.
1 parent ed00d33 commit 3cd77d8

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

internal/provider/bootstrap_service_account.go

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func GenerateBootstrapServiceAccountToken(
1919
return "", fmt.Errorf("shared_secret is invalid: %w", err)
2020
}
2121

22+
if len(sharedSecret) == 0 {
23+
return "", fmt.Errorf("shared_secret is empty")
24+
}
25+
2226
sig, err := jose.NewSigner(jose.SigningKey{Algorithm: jose.HS256, Key: sharedSecret},
2327
(&jose.SignerOptions{}).WithType("JWT"))
2428
if err != nil {

internal/provider/bootstrap_service_account_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func TestGenerateBootstrapServiceAccountToken(t *testing.T) {
3333
require.Len(t, parts, 3)
3434
},
3535
},
36+
{
37+
name: "empty secret",
38+
sharedSecret: "",
39+
expectError: true,
40+
},
3641
}
3742

3843
for _, tt := range tests {

internal/provider/provider.go

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (p *PomeriumProvider) Configure(ctx context.Context, req provider.Configure
112112
var token string
113113
if !data.ServiceAccountToken.IsNull() {
114114
token = data.ServiceAccountToken.ValueString()
115+
if token == "" {
116+
resp.Diagnostics.AddError("service_account_token is empty", "service_account_token is empty")
117+
return
118+
}
115119
} else if !data.SharedSecretB64.IsNull() {
116120
token, err = GenerateBootstrapServiceAccountToken(data.SharedSecretB64.ValueString())
117121
if err != nil {

0 commit comments

Comments
 (0)