provider_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. Copyright © The ESO Authors
  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. https://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 senhasegura
  14. import (
  15. "testing"
  16. "github.com/stretchr/testify/assert"
  17. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  18. )
  19. func TestValidateStore(t *testing.T) {
  20. tbl := []struct {
  21. test string
  22. store esv1.GenericStore
  23. expErr bool
  24. }{
  25. {
  26. test: "should not create provider due to nil store",
  27. store: nil,
  28. expErr: true,
  29. },
  30. {
  31. test: "should not create provider due to missing provider",
  32. expErr: true,
  33. store: &esv1.SecretStore{
  34. Spec: esv1.SecretStoreSpec{},
  35. },
  36. },
  37. {
  38. test: "should not create provider due to missing provider field",
  39. expErr: true,
  40. store: &esv1.SecretStore{
  41. Spec: esv1.SecretStoreSpec{
  42. Provider: &esv1.SecretStoreProvider{},
  43. },
  44. },
  45. },
  46. {
  47. test: "should not create provider due to missing provider module",
  48. expErr: true,
  49. store: &esv1.SecretStore{
  50. Spec: esv1.SecretStoreSpec{
  51. Provider: &esv1.SecretStoreProvider{
  52. Senhasegura: &esv1.SenhaseguraProvider{},
  53. },
  54. },
  55. },
  56. },
  57. {
  58. test: "should not create provider due to missing provider auth client ID",
  59. expErr: true,
  60. store: &esv1.SecretStore{
  61. Spec: esv1.SecretStoreSpec{
  62. Provider: &esv1.SecretStoreProvider{
  63. Senhasegura: &esv1.SenhaseguraProvider{
  64. Module: esv1.SenhaseguraModuleDSM,
  65. },
  66. },
  67. },
  68. },
  69. },
  70. {
  71. test: "invalid module should return an error",
  72. expErr: true,
  73. store: &esv1.SecretStore{
  74. Spec: esv1.SecretStoreSpec{
  75. Provider: &esv1.SecretStoreProvider{
  76. Senhasegura: &esv1.SenhaseguraProvider{
  77. Module: "HIHIHIHHEHEHEHEHEHE",
  78. },
  79. },
  80. },
  81. },
  82. },
  83. {
  84. test: "should not create provider due senhasegura URL without https scheme",
  85. expErr: true,
  86. store: &esv1.SecretStore{
  87. Spec: esv1.SecretStoreSpec{
  88. Provider: &esv1.SecretStoreProvider{
  89. Senhasegura: &esv1.SenhaseguraProvider{
  90. Module: esv1.SenhaseguraModuleDSM,
  91. URL: "http://dev.null",
  92. },
  93. },
  94. },
  95. },
  96. },
  97. {
  98. test: "should not create provider due senhasegura URL without valid name",
  99. expErr: true,
  100. store: &esv1.SecretStore{
  101. Spec: esv1.SecretStoreSpec{
  102. Provider: &esv1.SecretStoreProvider{
  103. Senhasegura: &esv1.SenhaseguraProvider{
  104. Module: esv1.SenhaseguraModuleDSM,
  105. URL: "https://",
  106. },
  107. },
  108. },
  109. },
  110. },
  111. {
  112. test: "should create provider",
  113. expErr: false,
  114. store: &esv1.SecretStore{
  115. Spec: esv1.SecretStoreSpec{
  116. Provider: &esv1.SecretStoreProvider{
  117. Senhasegura: &esv1.SenhaseguraProvider{
  118. Module: esv1.SenhaseguraModuleDSM,
  119. URL: "https://senhasegura.local",
  120. Auth: esv1.SenhaseguraAuth{
  121. ClientID: "example",
  122. },
  123. },
  124. },
  125. },
  126. },
  127. },
  128. }
  129. for i := range tbl {
  130. row := tbl[i]
  131. t.Run(row.test, func(t *testing.T) {
  132. err := validateStore(row.store)
  133. if row.expErr {
  134. assert.Error(t, err)
  135. } else {
  136. assert.Nil(t, err)
  137. }
  138. })
  139. }
  140. }