Skip to content

Commit 5cfbcc7

Browse files
[SPC] Update tests for new output states (#53386)
See w3c/secure-payment-confirmation#292
1 parent fe1c32a commit 5cfbcc7

File tree

2 files changed

+112
-3
lines changed

2 files changed

+112
-3
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>Test for the 'secure-payment-confirmation' payment method authentication - user wants to auth another way case</title>
4+
<link rel="help" href="https://w3c.github.io/secure-payment-confirmation/#sctn-transaction-confirmation-outcome">
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/resources/testdriver.js"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="utils.sub.js"></script>
10+
<script>
11+
'use strict';
12+
13+
promise_test(async t => {
14+
await window.test_driver.set_spc_transaction_mode("autoChooseToAuthAnotherWay");
15+
t.add_cleanup(() => {
16+
return window.test_driver.set_spc_transaction_mode("none");
17+
});
18+
19+
const challenge = 'server challenge';
20+
const payeeOrigin = 'https://merchant.com';
21+
const displayName = 'Troycard ***1234';
22+
const request = new PaymentRequest([{
23+
supportedMethods: 'secure-payment-confirmation',
24+
data: {
25+
credentialIds: [Uint8Array.from('nonexistent', c => c.charCodeAt(0))],
26+
challenge: Uint8Array.from(challenge, c => c.charCodeAt(0)),
27+
rpId: window.location.hostname,
28+
payeeOrigin,
29+
timeout: 60000,
30+
instrument: {
31+
displayName,
32+
icon: ICON_URL,
33+
},
34+
}
35+
}], PAYMENT_DETAILS);
36+
37+
await test_driver.bless('user activation');
38+
return promise_rejects_dom(t, "NotAllowedError", request.show());
39+
}, 'Choose to auth another way without matching credential');
40+
41+
promise_test(async t => {
42+
const authenticator = await window.test_driver.add_virtual_authenticator(
43+
AUTHENTICATOR_OPTS);
44+
t.add_cleanup(() => {
45+
return window.test_driver.remove_virtual_authenticator(authenticator);
46+
});
47+
48+
await window.test_driver.set_spc_transaction_mode("autoChooseToAuthAnotherWay");
49+
t.add_cleanup(() => {
50+
return window.test_driver.set_spc_transaction_mode("none");
51+
});
52+
53+
const credential = await createCredential();
54+
55+
const challenge = 'server challenge';
56+
const payeeOrigin = 'https://merchant.com';
57+
const displayName = 'Troycard ***1234';
58+
const request = new PaymentRequest([{
59+
supportedMethods: 'secure-payment-confirmation',
60+
data: {
61+
credentialIds: [credential.rawId],
62+
challenge: Uint8Array.from(challenge, c => c.charCodeAt(0)),
63+
rpId: window.location.hostname,
64+
payeeOrigin,
65+
timeout: 60000,
66+
instrument: {
67+
displayName,
68+
icon: ICON_URL,
69+
},
70+
}
71+
}], PAYMENT_DETAILS);
72+
73+
await test_driver.bless('user activation');
74+
return promise_rejects_dom(t, "NotAllowedError", request.show());
75+
}, 'Choose to auth another way when credential matched');
76+
</script>

secure-payment-confirmation/authentication-rejected.https.html

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<meta charset="utf-8">
33
<title>Test for the 'secure-payment-confirmation' payment method authentication - user rejects case</title>
4-
<link rel="help" href="https://w3c.github.io/secure-payment-confirmation/sctn-authentication">
4+
<link rel="help" href="https://w3c.github.io/secure-payment-confirmation/#sctn-transaction-confirmation-outcome">
55
<script src="/resources/testharness.js"></script>
66
<script src="/resources/testharnessreport.js"></script>
77
<script src="/resources/testdriver.js"></script>
@@ -22,6 +22,39 @@
2222
return window.test_driver.set_spc_transaction_mode("none");
2323
});
2424

25+
const challenge = 'server challenge';
26+
const payeeOrigin = 'https://merchant.com';
27+
const displayName = 'Troycard ***1234';
28+
const request = new PaymentRequest([{
29+
supportedMethods: 'secure-payment-confirmation',
30+
data: {
31+
credentialIds: [Uint8Array.from('nonexistent', c => c.charCodeAt(0))],
32+
challenge: Uint8Array.from(challenge, c => c.charCodeAt(0)),
33+
rpId: window.location.hostname,
34+
payeeOrigin,
35+
timeout: 60000,
36+
instrument: {
37+
displayName,
38+
icon: ICON_URL,
39+
},
40+
}
41+
}], PAYMENT_DETAILS);
42+
43+
await test_driver.bless('user activation');
44+
return promise_rejects_dom(t, "AbortError", request.show());
45+
}, 'Rejected SPC authentication without matching credential');
46+
47+
promise_test(async t => {
48+
const authenticator = await window.test_driver.add_virtual_authenticator(
49+
AUTHENTICATOR_OPTS);
50+
t.add_cleanup(() => {
51+
return window.test_driver.remove_virtual_authenticator(authenticator);
52+
});
53+
54+
await window.test_driver.set_spc_transaction_mode("autoReject");
55+
t.add_cleanup(() => {
56+
return window.test_driver.set_spc_transaction_mode("none");
57+
});
2558

2659
const credential = await createCredential();
2760

@@ -44,6 +77,6 @@
4477
}], PAYMENT_DETAILS);
4578

4679
await test_driver.bless('user activation');
47-
return promise_rejects_dom(t, "NotAllowedError", request.show());
48-
}, 'Rejected SPC authentication');
80+
return promise_rejects_dom(t, "AbortError", request.show());
81+
}, 'Rejected SPC authentication when credential matched');
4982
</script>

0 commit comments

Comments
 (0)