Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix switch case config validation #14

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/lib/config/sms_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ var _ = RootSchema.Add("ProviderSelectorSwitchRule", `
},
"allOf": [
{
"if": { "properties": { "type": { "const": "phone_number_alpha2" } }},
"if": { "properties": { "type": { "const": "match_phone_number_alpha2" } }},
"then": { "required": ["phone_number_alpha2"] }
},
{
"if": { "properties": { "type": { "const": "app_id_and_phone_number_alpha2" } }},
"then": { "required": ["phone_number_alpha2"] }
"if": { "properties": { "type": { "const": "match_app_id_and_phone_number_alpha2" } }},
"then": { "required": ["phone_number_alpha2", "app_id"] }
}
],
"required": ["type", "use_provider"]
Expand Down
24 changes: 24 additions & 0 deletions pkg/lib/config/testdata/authgear-sms-gateway.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,27 @@ config:
switch:
- type: default
use_provider: twilio
---
name: missing-required-fields-in-switch-cases
error: |-
invalid configuration:
/provider_selector/switch/0: required
map[actual:[type use_provider] expected:[phone_number_alpha2] missing:[phone_number_alpha2]]
/provider_selector/switch/1: required
map[actual:[type use_provider] expected:[app_id phone_number_alpha2] missing:[app_id phone_number_alpha2]]
config:
providers:
- name: twilio
type: twilio
twilio:
account_sid: "my-account-sid"
auth_token: "my-auth-token"
messaging_service_sid: "my-messaging-service-sid"
provider_selector:
switch:
- type: match_phone_number_alpha2
use_provider: twilio
- type: match_app_id_and_phone_number_alpha2
use_provider: twilio
- type: default
use_provider: twilio
2 changes: 1 addition & 1 deletion pkg/lib/sms/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ provider_selector:
use_provider: p2
phone_number_alpha2: CN
app_id: "123"
- type: match_app_id_and_phone_number_alpha2
- type: match_phone_number_alpha2
use_provider: p4
phone_number_alpha2: CN
- type: default
Expand Down
Loading