feat: add Airwallex payments and multi-currency support
This commit is contained in:
@@ -330,6 +330,52 @@ func TestEnhanceCSPPolicy(t *testing.T) {
|
||||
assert.NotContains(t, enhanced, NonceTemplate)
|
||||
assert.Contains(t, enhanced, "'nonce-existing'")
|
||||
})
|
||||
|
||||
t.Run("adds_airwallex_domains_for_payment_sdk", func(t *testing.T) {
|
||||
policy := "default-src 'self'; script-src 'self' __CSP_NONCE__; style-src 'self'; frame-src 'self'"
|
||||
enhanced := enhanceCSPPolicy(policy)
|
||||
|
||||
assert.Contains(t, enhanced, "script-src 'self' __CSP_NONCE__")
|
||||
assert.Contains(t, enhanced, AirwallexStaticDomain)
|
||||
assert.Contains(t, enhanced, AirwallexCheckoutDomain)
|
||||
assert.Contains(t, enhanced, AirwallexDemoStaticDomain)
|
||||
assert.Contains(t, enhanced, AirwallexDemoCheckoutDomain)
|
||||
assert.Contains(t, enhanced, "style-src 'self'")
|
||||
assert.Contains(t, enhanced, "frame-src 'self'")
|
||||
})
|
||||
|
||||
t.Run("does_not_duplicate_airwallex_domains", func(t *testing.T) {
|
||||
policy := "default-src 'self'; script-src 'self' https://static.airwallex.com https://static-demo.airwallex.com; frame-src https://checkout.airwallex.com https://checkout-demo.airwallex.com"
|
||||
enhanced := enhanceCSPPolicy(policy)
|
||||
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "script-src", AirwallexStaticDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "script-src", AirwallexCheckoutDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "style-src", AirwallexStaticDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "style-src", AirwallexCheckoutDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "frame-src", AirwallexCheckoutDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "script-src", AirwallexDemoStaticDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "script-src", AirwallexDemoCheckoutDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "style-src", AirwallexDemoStaticDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "style-src", AirwallexDemoCheckoutDomain))
|
||||
assert.Equal(t, 1, countDirectiveValue(enhanced, "frame-src", AirwallexDemoCheckoutDomain))
|
||||
})
|
||||
}
|
||||
|
||||
func countDirectiveValue(policy, directive, value string) int {
|
||||
for _, rawDirective := range strings.Split(policy, ";") {
|
||||
fields := strings.Fields(strings.TrimSpace(rawDirective))
|
||||
if len(fields) == 0 || fields[0] != directive {
|
||||
continue
|
||||
}
|
||||
count := 0
|
||||
for _, field := range fields[1:] {
|
||||
if field == value {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestAddToDirective(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user