Skip to content

Commit

Permalink
chore: remove unused code (#6674)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Nov 14, 2024
1 parent 5c29229 commit 9bafdb4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 71 deletions.
18 changes: 0 additions & 18 deletions internal/admission/validation/consumers/credentials/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,6 @@ func ValidateCredentials(secret *corev1.Secret) error {
return nil
}

// IsKeyUniqueConstrained indicates whether or not a given key and its type there
// are unique constraints in place.
func IsKeyUniqueConstrained(keyType, key string) (constrained bool) {
constrainedKeys, credTypeHasConstraints := uniqueKeyConstraints[keyType]
if !credTypeHasConstraints {
return
}

for _, constrainedKey := range constrainedKeys {
if key == constrainedKey {
constrained = true
return
}
}

return
}

// -----------------------------------------------------------------------------
// Validation - Credentials
// -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,6 @@ import (
"github.com/kong/kubernetes-ingress-controller/v3/internal/labels"
)

func TestUniqueConstraintsValidation(t *testing.T) {
t.Log("Setting up an index of existing credentials which have unique constraints")
index := make(Index)
require.NoError(t, index.add(Credential{
Key: "username",
Value: "batman",
Type: "basic-auth",
}))
require.NoError(t, index.add(Credential{
Key: "username",
Value: "robin",
Type: "basic-auth",
}))

t.Log("Verifying that a new basic-auth credential with a unique username doesn't violate constraints")
nonviolatingCredential := Credential{
Key: "username",
Value: "nightwing",
Type: "basic-auth",
}
assert.NoError(t, index.add(nonviolatingCredential))

t.Log("Verifying that a new basic-auth credential with a username that's already in use violates constraints")
violatingCredential := Credential{
Key: "username",
Value: "batman",
Type: "basic-auth",
}
assert.True(t, IsKeyUniqueConstrained(violatingCredential.Type, violatingCredential.Key))
err := index.add(violatingCredential)
assert.Error(t, err)

t.Log("Setting up a list of existing credentials which have no unique constraints")
index = make(Index)
assert.NoError(t, index.add(Credential{
Key: "key",
Value: "test",
Type: "acl",
}))

t.Log("Verifying that non-unique constrained credentials don't trigger a violation")
duplicate := Credential{
Key: "key",
Value: "test",
Type: "acl",
}
assert.False(t, IsKeyUniqueConstrained(duplicate.Type, duplicate.Key))
assert.NoError(t, index.add(duplicate))

t.Log("Verifying that unconstrained keys for types with constraints don't flag as violated")
assert.False(t, IsKeyUniqueConstrained("basic-auth", "unconstrained-key"))
}

func TestValidateCredentials(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 9bafdb4

Please sign in to comment.