Skip to content

Commit

Permalink
fix: initialise test otp to an empty map (#2919)
Browse files Browse the repository at this point in the history
* fix: initialise test otp to an empty map

* chore: update unit tests

* chore: updater tests
  • Loading branch information
sweatybridge authored Nov 26, 2024
1 parent 949b018 commit ab95a72
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
13 changes: 5 additions & 8 deletions pkg/config/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func newWithDefaults() auth {
Email: email{
EnableConfirmations: true,
},
Sms: sms{
TestOTP: map[string]string{},
},
}
}

Expand Down Expand Up @@ -563,9 +566,7 @@ func TestSmsDiff(t *testing.T) {
// This is not a valid config because platform requires a SMS provider.
// For consistency, we handle this in config.Load and emit a warning.
c := newWithDefaults()
c.Sms = sms{
EnableSignup: true,
}
c.Sms.EnableSignup = true
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(false),
Expand All @@ -578,11 +579,7 @@ func TestSmsDiff(t *testing.T) {

t.Run("enable provider without sign up", func(t *testing.T) {
c := newWithDefaults()
c.Sms = sms{
Messagebird: messagebirdConfig{
Enabled: true,
},
}
c.Sms.Messagebird.Enabled = true
// Run test
diff, err := c.DiffWithRemote("", v1API.AuthConfigResponse{
ExternalPhoneEnabled: cast.Ptr(false),
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ func NewConfig(editors ...ConfigEditor) config {
"reauthentication": {},
},
},
Sms: sms{
TestOTP: map[string]string{},
},
External: map[string]provider{
"apple": {},
"azure": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff remote[auth] local[auth]
--- remote[auth]
+++ local[auth]
@@ -88,7 +88,7 @@
@@ -89,7 +89,7 @@

[external]
[external.apple]
Expand All @@ -10,7 +10,7 @@ diff remote[auth] local[auth]
client_id = "test-client-1,test-client-2"
secret = "hash:ce62bb9bcced294fd4afe668f8ab3b50a89cf433093c526fffa3d0e46bf55252"
url = ""
@@ -144,7 +144,7 @@
@@ -145,7 +145,7 @@
redirect_uri = ""
skip_nonce_check = false
[external.google]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ diff remote[auth] local[auth]
account_sid = ""
message_service_sid = ""
auth_token = ""
@@ -85,9 +85,6 @@
from = ""
@@ -86,8 +86,6 @@
api_key = ""
api_secret = ""
-[sms.test_otp]
[sms.test_otp]
-123 = "456"
-456 = "123"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ diff remote[auth] local[auth]
[sms.textlocal]
enabled = false
sender = ""
@@ -85,6 +85,8 @@
from = ""
@@ -86,6 +86,7 @@
api_key = ""
api_secret = ""
+[sms.test_otp]
[sms.test_otp]
+123 = "456"

[third_party]
Expand Down
1 change: 1 addition & 0 deletions pkg/config/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func TestUpdateAuthConfig(t *testing.T) {
Enabled: true,
EnableSignup: true,
Email: email{EnableConfirmations: true},
Sms: sms{TestOTP: map[string]string{}},
})
// Check result
assert.NoError(t, err)
Expand Down
3 changes: 0 additions & 3 deletions pkg/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ func mapToEnv(input map[string]string) string {

func envToMap(input string) map[string]string {
env := strToArr(input)
if len(env) == 0 {
return nil
}
result := make(map[string]string, len(env))
for _, kv := range env {
if parts := strings.Split(kv, "="); len(parts) > 1 {
Expand Down

0 comments on commit ab95a72

Please sign in to comment.