1
+ // <copyright file="DesiredCapabilities.cs" company="WebDriver Committers">
2
+ // Licensed to the Software Freedom Conservancy (SFC) under one
3
+ // or more contributor license agreements. See the NOTICE file
4
+ // distributed with this work for additional information
5
+ // regarding copyright ownership. The SFC licenses this file
6
+ // to you under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ // </copyright>
18
+
19
+ using System ;
20
+ using System . Collections . Generic ;
21
+
22
+ namespace OpenQA . Selenium . VirtualAuth
23
+ {
24
+ /// <summary>
25
+ /// Options for the creation of virtual authenticators.
26
+ /// Refer https://w3c.github.io/webauthn/#sctn-automation
27
+ /// </summary>
28
+ public class VirtualAuthenticatorOptions
29
+ {
30
+ public static class Protocol
31
+ {
32
+ public static readonly string CTAP2 = "ctap2" ;
33
+ public static readonly string U2F = "ctap1/u2f" ;
34
+ }
35
+
36
+ public static class Transport
37
+ {
38
+ public static readonly string BLE = "ble" ;
39
+ public static readonly string INTERNAL = "internal" ;
40
+ public static readonly string NFC = "nfc" ;
41
+ public static readonly string USB = "usb" ;
42
+ }
43
+
44
+ private string protocol = Protocol . CTAP2 ;
45
+ private string transport = Transport . USB ;
46
+ private bool hasResidentKey = false ;
47
+ private bool hasUserVerification = false ;
48
+ private bool isUserConsenting = true ;
49
+ private bool isUserVerified = false ;
50
+
51
+ /// <summary>
52
+ /// Sets the protocol the Virtual Authenticator speaks
53
+ /// </summary>
54
+ /// <param name="protocol">Valid protocol value</param>
55
+ /// <returns>VirtualAuthenticatorOptions</returns>
56
+ public VirtualAuthenticatorOptions SetProtocol ( string protocol )
57
+ {
58
+ if ( string . Equals ( Protocol . CTAP2 , protocol ) || string . Equals ( Protocol . U2F , protocol ) )
59
+ {
60
+ this . protocol = protocol ;
61
+ return this ;
62
+ }
63
+ else
64
+ {
65
+ throw new ArgumentException ( "Enter a valid protocol value." +
66
+ "Refer to https://www.w3.org/TR/webauthn-2/#sctn-automation-virtual-authenticators for supported protocols." ) ;
67
+ }
68
+ }
69
+
70
+ /// <summary>
71
+ /// Sets the transport authenticator needs to implement to communicate with clients
72
+ /// </summary>
73
+ /// <param name="transport">Valid transport value</param>
74
+ /// <returns>VirtualAuthenticatorOptions</returns>
75
+ public VirtualAuthenticatorOptions SetTransport ( string transport )
76
+ {
77
+ if ( Transport . BLE . Equals ( transport ) ||
78
+ Transport . INTERNAL . Equals ( transport ) ||
79
+ Transport . NFC . Equals ( transport ) ||
80
+ Transport . USB . Equals ( transport ) )
81
+ {
82
+ this . transport = transport ;
83
+ return this ;
84
+ }
85
+ else
86
+ {
87
+ throw new ArgumentException ( "Enter a valid transport value." +
88
+ "Refer to https://www.w3.org/TR/webauthn-2/#enum-transport for supported transport values." ) ;
89
+ }
90
+ }
91
+
92
+ /// <summary>
93
+ /// If set to true the authenticator will support client-side discoverable credentials.
94
+ /// Refer https://w3c.github.io/webauthn/#client-side-discoverable-credential
95
+ /// </summary>
96
+ /// <param name="hasResidentKey">boolean value to set</param>
97
+ /// <returns>VirtualAuthenticatorOptions</returns>
98
+ public VirtualAuthenticatorOptions SetHasResidentKey ( bool hasResidentKey )
99
+ {
100
+ this . hasResidentKey = hasResidentKey ;
101
+ return this ;
102
+ }
103
+
104
+ /// <summary>
105
+ /// If set to true, the authenticator supports user verification.
106
+ /// Refer https://w3c.github.io/webauthn/#user-verification.
107
+ /// </summary>
108
+ /// <param name="hasUserVerification">boolean value to set</param>
109
+ /// <returns></returns>
110
+ public VirtualAuthenticatorOptions SetHasUserVerification ( bool hasUserVerification )
111
+ {
112
+ this . hasUserVerification = hasUserVerification ;
113
+ return this ;
114
+ }
115
+
116
+ /// <summary>
117
+ /// If set to true, a user consent will always be granted.
118
+ /// Refer https://w3c.github.io/webauthn/#user-consent
119
+ /// </summary>
120
+ /// <param name="isUserConsenting">boolean value to set</param>
121
+ /// <returns>VirtualAuthenticatorOptions</returns>
122
+ public VirtualAuthenticatorOptions SetIsUserConsenting ( bool isUserConsenting )
123
+ {
124
+ this . isUserConsenting = isUserConsenting ;
125
+ return this ;
126
+ }
127
+
128
+ /// <summary>
129
+ /// If set to true, User Verification will always succeed.
130
+ /// Refer https://w3c.github.io/webauthn/#user-verification
131
+ /// </summary>
132
+ /// <param name="isUserVerified">boolean value to set</param>
133
+ /// <returns>VirtualAuthenticatorOptions</returns>
134
+ public VirtualAuthenticatorOptions SetIsUserVerified ( bool isUserVerified )
135
+ {
136
+ this . isUserVerified = isUserVerified ;
137
+ return this ;
138
+ }
139
+
140
+ public Dictionary < string , object > ToDictionary ( )
141
+ {
142
+ Dictionary < string , object > toReturn = new Dictionary < string , object > ( ) ;
143
+
144
+ toReturn [ "protocol" ] = this . protocol ;
145
+ toReturn [ "transport" ] = this . transport ;
146
+ toReturn [ "hasResidentKey" ] = this . hasResidentKey ;
147
+ toReturn [ "hasUserVerification" ] = this . hasUserVerification ;
148
+ toReturn [ "isUserConsenting" ] = this . isUserConsenting ;
149
+ toReturn [ "isUserVerified" ] = this . isUserVerified ;
150
+
151
+ return toReturn ;
152
+ }
153
+ }
154
+ }
0 commit comments