482485733c5af37238321b6f24b22034dfed4b71
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-create-failure-nfc.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[create]] failure cases with a mock nfc authenticator.</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script src="./resources/util.js"></script>
6 <script>
7     // Default mock configuration. Tests need to override it if they need different configuration.
8     if (window.testRunner)
9         testRunner.setWebAuthenticationMockConfiguration({ nfc: { error: "no-tags" } });
10
11     promise_test(function(t) {
12         const options = {
13             publicKey: {
14                 rp: {
15                     name: "example.com"
16                 },
17                 user: {
18                     name: "John Appleseed",
19                     id: asciiToUint8Array("123456"),
20                     displayName: "John",
21                 },
22                 challenge: asciiToUint8Array("123456"),
23                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
24                 timeout: 10,
25                 authenticatorSelection: { authenticatorAttachment: "platform" }
26             }
27         };
28
29         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
30     }, "PublicKeyCredential's [[create]] with timeout in a mock nfc authenticator.");
31
32     promise_test(function(t) {
33         const options = {
34             publicKey: {
35                 rp: {
36                     name: "example.com"
37                 },
38                 user: {
39                     name: "John Appleseed",
40                     id: asciiToUint8Array("123456"),
41                     displayName: "John",
42                 },
43                 challenge: asciiToUint8Array("123456"),
44                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
45                 timeout: 10
46             }
47         };
48
49         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
50     }, "PublicKeyCredential's [[create]] with no tags in a mock nfc authenticator.");
51
52     promise_test(function(t) {
53         const options = {
54             publicKey: {
55                 rp: {
56                     name: "example.com"
57                 },
58                 user: {
59                     name: "John Appleseed",
60                     id: asciiToUint8Array("123456"),
61                     displayName: "John",
62                 },
63                 challenge: asciiToUint8Array("123456"),
64                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
65                 timeout: 10
66             }
67         };
68
69         if (window.testRunner)
70             testRunner.setWebAuthenticationMockConfiguration({ nfc: { error: "wrong-tag-type" } });
71         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
72     }, "PublicKeyCredential's [[create]] with wrong tag type in a mock nfc authenticator.");
73
74     promise_test(function(t) {
75         const options = {
76             publicKey: {
77                 rp: {
78                     name: "example.com"
79                 },
80                 user: {
81                     name: "John Appleseed",
82                     id: asciiToUint8Array("123456"),
83                     displayName: "John",
84                 },
85                 challenge: asciiToUint8Array("123456"),
86                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
87                 timeout: 10
88             }
89         };
90
91         if (window.testRunner)
92             testRunner.setWebAuthenticationMockConfiguration({ nfc: { error: "no-connections" } });
93         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
94     }, "PublicKeyCredential's [[create]] with no connections in a mock nfc authenticator.");
95
96     promise_test(function(t) {
97         const options = {
98             publicKey: {
99                 rp: {
100                     name: "example.com"
101                 },
102                 user: {
103                     name: "John Appleseed",
104                     id: asciiToUint8Array("123456"),
105                     displayName: "John",
106                 },
107                 challenge: asciiToUint8Array("123456"),
108                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
109                 timeout: 10
110             }
111         };
112
113         if (window.testRunner)
114             testRunner.setWebAuthenticationMockConfiguration({ nfc: { error: "malicious-payload", payloadBase64: [ ] } });
115         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
116     }, "PublicKeyCredential's [[create]] with null version in a mock nfc authenticator.");
117
118     promise_test(function(t) {
119         const options = {
120             publicKey: {
121                 rp: {
122                     name: "example.com"
123                 },
124                 user: {
125                     name: "John Appleseed",
126                     id: asciiToUint8Array("123456"),
127                     displayName: "John",
128                 },
129                 challenge: asciiToUint8Array("123456"),
130                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
131                 timeout: 10
132             }
133         };
134
135         if (window.testRunner)
136             testRunner.setWebAuthenticationMockConfiguration({ nfc: { error: "malicious-payload", payloadBase64:[testDummyMessagePayloadBase64] } });
137         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
138     }, "PublicKeyCredential's [[create]] with wrong version in a mock nfc authenticator.");
139
140 </script>