security_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Copyright 2021 The Rook Authors. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6.     http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package v1
  14. import "testing"
  15. func TestKeyManagementServiceSpec_IsK8sAuthEnabled(t *testing.T) {
  16. type fields struct {
  17. ConnectionDetails map[string]string
  18. TokenSecretName string
  19. }
  20. tests := []struct {
  21. name string
  22. fields fields
  23. want bool
  24. }{
  25. {"k8s auth is disabled - everything is empty", fields{ConnectionDetails: map[string]string{}, TokenSecretName: ""}, false},
  26. {"k8s auth is disabled - token is populated", fields{ConnectionDetails: map[string]string{}, TokenSecretName: "foo"}, false},
  27. {"k8s auth is disabled since token is provided", fields{ConnectionDetails: map[string]string{"VAULT_AUTH_METHOD": "kubernetes"}, TokenSecretName: "rook-ceph-test-secret"}, false},
  28. {"k8s auth is disabled since VAULT_AUTH_METHOD is unknown", fields{ConnectionDetails: map[string]string{"VAULT_AUTH_METHOD": "foo"}, TokenSecretName: ""}, false},
  29. {"k8s auth is enabled", fields{ConnectionDetails: map[string]string{"VAULT_AUTH_METHOD": "kubernetes"}, TokenSecretName: ""}, true},
  30. }
  31. for _, tt := range tests {
  32. t.Run(tt.name, func(t *testing.T) {
  33. kms := &KeyManagementServiceSpec{
  34. ConnectionDetails: tt.fields.ConnectionDetails,
  35. TokenSecretName: tt.fields.TokenSecretName,
  36. }
  37. if got := kms.IsK8sAuthEnabled(); got != tt.want {
  38. t.Errorf("KeyManagementServiceSpec.IsK8sAuthEnabled() = %v, want %v", got, tt.want)
  39. }
  40. })
  41. }
  42. }