@deque/axe-appium3-webdriveragent 1.7.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/WebDriverAgent.xcodeproj/project.pbxproj +61 -3
  3. package/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.h +4 -1
  4. package/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +35 -2
  5. package/WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.h +6 -0
  6. package/WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m +100 -23
  7. package/WebDriverAgentLib/Categories/XCUIDevice+FBRotation.m +8 -3
  8. package/WebDriverAgentLib/Categories/XCUIElement+FBTyping.h +7 -0
  9. package/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m +20 -0
  10. package/WebDriverAgentLib/Commands/AxeAuthCommands.h +4 -0
  11. package/WebDriverAgentLib/Commands/AxeAuthCommands.m +113 -56
  12. package/WebDriverAgentLib/Commands/AxeAutoScanCommands.m +1 -7
  13. package/WebDriverAgentLib/Commands/AxeScanCommands.m +57 -315
  14. package/WebDriverAgentLib/Commands/FBCustomCommands.m +8 -0
  15. package/WebDriverAgentLib/Commands/FBElementCommands.m +12 -5
  16. package/WebDriverAgentLib/Commands/FBSessionCommands.m +1 -1
  17. package/WebDriverAgentLib/Info.plist +2 -2
  18. package/WebDriverAgentLib/Routing/FBSession.m +2 -2
  19. package/WebDriverAgentLib/Utilities/FBConfiguration.h +2 -0
  20. package/WebDriverAgentLib/Utilities/FBConfiguration.m +1 -0
  21. package/WebDriverAgentLib/Utilities/FBHIDOperations.h +41 -0
  22. package/WebDriverAgentLib/Utilities/FBHIDOperations.m +244 -0
  23. package/WebDriverAgentLib/Utilities/FBSettings.h +1 -0
  24. package/WebDriverAgentLib/Utilities/FBSettings.m +1 -0
  25. package/WebDriverAgentLib/Utilities/FBSettingsHandler.m +26 -2
  26. package/WebDriverAgentTests/IntegrationApp/Classes/ViewController.m +11 -7
  27. package/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m +44 -0
  28. package/WebDriverAgentTests/IntegrationTests/FBTypingTest.m +33 -0
  29. package/WebDriverAgentTests/IntegrationTests/XCUIApplicationHelperTests.m +111 -0
  30. package/WebDriverAgentTests/IntegrationTests/XCUIDeviceHelperTests.m +97 -0
  31. package/WebDriverAgentTests/IntegrationTests/XCUIDeviceRotationTests.m +53 -0
  32. package/WebDriverAgentTests/IntegrationTests_tvOS/FBTVFocusIntegrationTests.m +21 -0
  33. package/WebDriverAgentTests/IntegrationTests_watchOS/WDAAppLifecycleIntegrationTests.swift +12 -0
  34. package/axeDevToolsXCUI.xcframework/Info.plist +3 -3
  35. package/axeDevToolsXCUI.xcframework/LICENSE-3RD-PARTY-axe-devtools-ios.md +1 -1
  36. package/axeDevToolsXCUI.xcframework/{axe-devtools-ios-4.3.1.cdx.json → axe-devtools-ios-5.0.0.cdx.json} +6 -6
  37. package/axeDevToolsXCUI.xcframework/{axe-devtools-ios-4.3.1.spdx.json → axe-devtools-ios-5.0.0.spdx.json} +5 -5
  38. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Headers/AxeTestBundleObserver.h +0 -1
  39. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Headers/axeDevToolsXCUI-Swift.h +82 -228
  40. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Info.plist +4 -4
  41. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.abi.json +3120 -5759
  42. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.private.swiftinterface +53 -168
  43. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  44. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios.swiftinterface +53 -168
  45. package/axeDevToolsXCUI.xcframework/ios-arm64/axeDevToolsXCUI.framework/axeDevToolsXCUI +0 -0
  46. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Headers/AxeTestBundleObserver.h +0 -1
  47. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Headers/axeDevToolsXCUI-Swift.h +164 -456
  48. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Info.plist +4 -4
  49. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.abi.json +3120 -5759
  50. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +53 -168
  51. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  52. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/arm64-apple-ios-simulator.swiftinterface +53 -168
  53. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.abi.json +3120 -5759
  54. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +53 -168
  55. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  56. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/Modules/axeDevToolsXCUI.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +53 -168
  57. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/_CodeSignature/CodeResources +25 -25
  58. package/axeDevToolsXCUI.xcframework/ios-arm64_x86_64-simulator/axeDevToolsXCUI.framework/axeDevToolsXCUI +0 -0
  59. package/build/lib/webdriveragent.d.ts.map +1 -1
  60. package/build/lib/webdriveragent.js +1 -2
  61. package/build/lib/webdriveragent.js.map +1 -1
  62. package/build/tsconfig.tsbuildinfo +1 -1
  63. package/lib/webdriveragent.ts +1 -2
  64. package/package.json +8 -10
@@ -16,6 +16,13 @@
16
16
 
17
17
  #import "MySwiftFramework/MySwiftFramework-Swift.h"
18
18
 
19
+ @interface AxeAuthCommands ()
20
+
21
+ /// Drops any session a previous caller left installed.
22
+ + (void)clearSharedSession;
23
+
24
+ @end
25
+
19
26
  @implementation AxeAuthCommands
20
27
 
21
28
  #pragma mark - <FBCommandHandler>
@@ -75,12 +82,98 @@ static NSString *credentialKey;
75
82
  credentialKey = [key isKindOfClass:[NSString class]] ? [key copy] : nil;
76
83
  }
77
84
 
85
+ + (void)clearSharedSession
86
+ {
87
+ [self setSharedAxeDevTools:nil];
88
+ [self setSharedHasUploadSession:NO];
89
+ [self setSharedUploadResults:YES];
90
+ [self setSharedCredentialKey:nil];
91
+ }
92
+
93
+ + (nullable id)settingNamed:(NSString *)key inSettings:(NSDictionary *)settings
94
+ {
95
+ id value = settings[key];
96
+ return value == [NSNull null] ? nil : value;
97
+ }
98
+
99
+ + (BOOL)isArrayOfStrings:(id)value
100
+ {
101
+ if (![value isKindOfClass:[NSArray class]]) {
102
+ return NO;
103
+ }
104
+ for (id item in value) {
105
+ if (![item isKindOfClass:[NSString class]]) {
106
+ return NO;
107
+ }
108
+ }
109
+ return YES;
110
+ }
111
+
112
+ /// An `axeError` message for an ignore setting of the wrong shape, or nil when every one supplied
113
+ /// is well formed. Checked before signing in, so a malformed request is rejected rather than
114
+ /// starting a session with some of its ignores missing.
115
+ + (nullable NSString *)ignoreSettingsErrorForSettings:(NSDictionary *)settings
116
+ {
117
+ id ignoreRules = [self settingNamed:@"ignoreRules" inSettings:settings];
118
+ if (ignoreRules != nil && ![self isArrayOfStrings:ignoreRules]) {
119
+ return @"'ignoreRules' should be an array of rule names.";
120
+ }
121
+
122
+ for (NSString *key in @[@"ignoreRulesOnElementIds", @"ignoreRulesOnElementClasses"]) {
123
+ id elementIgnores = [self settingNamed:key inSettings:settings];
124
+ if (elementIgnores == nil) {
125
+ continue;
126
+ }
127
+ NSString *shapeError = [NSString stringWithFormat:@"'%@' should be an object that maps each element to an array of rule names.", key];
128
+ if (![elementIgnores isKindOfClass:[NSDictionary class]]) {
129
+ return shapeError;
130
+ }
131
+ for (id element in elementIgnores) {
132
+ if (![element isKindOfClass:[NSString class]] || ![self isArrayOfStrings:elementIgnores[element]]) {
133
+ return shapeError;
134
+ }
135
+ }
136
+ }
137
+ return nil;
138
+ }
139
+
140
+ /// Hands the session's ignore settings to the SDK, which resolves the rule names, logs and skips
141
+ /// any it does not know, and applies the organization's `allowUserOverrides` setting to the
142
+ /// rule-level ignores. Called after sign-in, which is when the SDK reads that setting.
143
+ + (void)applyIgnoreSettings:(NSDictionary *)settings toInstance:(AxeDevTools *)instance
144
+ {
145
+ NSArray<NSString *> *ignoreRules = [self settingNamed:@"ignoreRules" inSettings:settings];
146
+ [instance ignoreRulesNamed:ignoreRules ?: @[]];
147
+
148
+ NSDictionary<NSString *, NSArray<NSString *> *> *byId = [self settingNamed:@"ignoreRulesOnElementIds" inSettings:settings];
149
+ [byId enumerateKeysAndObjectsUsingBlock:^(NSString *elementId, NSArray<NSString *> *names, BOOL *stop) {
150
+ [instance ignoreRulesNamed:names onElementWithId:elementId];
151
+ }];
152
+
153
+ NSDictionary<NSString *, NSArray<NSString *> *> *byClass = [self settingNamed:@"ignoreRulesOnElementClasses" inSettings:settings];
154
+ [byClass enumerateKeysAndObjectsUsingBlock:^(NSString *className, NSArray<NSString *> *names, BOOL *stop) {
155
+ [instance ignoreRulesNamed:names onElementOfClass:className];
156
+ }];
157
+ }
158
+
78
159
  + (id<FBResponsePayload>)handleAxeAuthCommand:(FBRouteRequest *)request
79
160
  {
161
+ // Replace any installed session before validation can reject this request: otherwise a
162
+ // rejected call leaves the previous caller's instance live, and the next /axeScan
163
+ // reuses it under the wrong account.
164
+ [self clearSharedSession];
165
+
80
166
  NSError *loginError = nil;
167
+ AxeDevTools *instance = nil;
168
+ BOOL sessionUploads = NO;
81
169
 
82
170
  NSDictionary *settings = request.arguments;
83
-
171
+
172
+ NSString *ignoreSettingsError = [self ignoreSettingsErrorForSettings:settings];
173
+ if (ignoreSettingsError) {
174
+ return FBResponseWithObject(@{ @"axeError": ignoreSettingsError });
175
+ }
176
+
84
177
  // required properties
85
178
  NSString *apiKey = settings[@"apiKey"];
86
179
  NSString *accessToken = settings[@"accessToken"] ?: @"";
@@ -90,70 +183,30 @@ static NSString *credentialKey;
90
183
 
91
184
  // optional properties with default values
92
185
  NSString *axeAccountURL = settings[@"axeAccountURL"] ?: @"";
93
- NSString *axeServiceUrl = settings[@"axeServiceUrl"] ?: @"";
94
186
  NSString *projectId = settings[@"projectId"] ?: @"";
95
- BOOL axeUploadResults = [settings[@"axeUploadResults"] ?: @YES boolValue]; // replacing uploadToDashboard on axeScan
187
+ BOOL axeUploadResults = [settings[@"axeUploadResults"] ?: @YES boolValue];
96
188
 
97
189
  #if AUTH
98
190
  if (accessToken.length > 0) {
99
191
  // OAuth access token authentication (used by MCP server)
100
- axeDevTools = [AxeDevTools loginWithAccessToken:accessToken axeAccountUrl:axeAccountURL error:&loginError];
101
- hasUploadSession = NO;
192
+ instance = [AxeDevTools loginWithAccessToken:accessToken axeAccountUrl:axeAccountURL error:&loginError];
193
+ sessionUploads = NO;
102
194
  axeUploadResults = NO;
195
+ } else if (axeUploadResults && projectId.length == 0) {
196
+ // Dev Hub uploads need a project to land in.
197
+ return FBResponseWithObject(@{ @"axeError": @"'projectId' is required in order to start a session when 'axeUploadResults' is true. Please provide your project ID from Axe Developer Hub, or set 'axeUploadResults' to false to keep results local." });
103
198
  } else {
104
- // 'axeServiceUrl' was set; follow mobile-service path
105
- if (axeAccountURL.length == 0 && axeServiceUrl.length > 0) {
106
- if (axeUploadResults && projectId.length > 0) {
107
- // This is an on-prem/private cloud customer who is trying to use their private old Mobile Service.
108
- NSLog(@"[axe-devtools] DEPRECATION: The mobile dashboard and the 'axeServiceUrl' settings property are being deprecated. Please migrate to Axe Developer Hub and provide an 'axeAccountURL'.");
109
- axeDevTools = [AxeDevTools startSessionWithApiKey:apiKey
110
- url:axeServiceUrl
111
- projectId:projectId
112
- error:&loginError];
113
-
114
- hasUploadSession = YES;
115
- } else {
116
- // Either we are not uploading, or there is no projectId to upload into.
117
- // Validate the credentials against the mobile service without creating a
118
- // session — mirrors the same case in AxeScanCommands (#361).
119
- NSLog(@"[axe-devtools] DEPRECATION: The mobile dashboard is being deprecated. Please set up your project in Axe Developer Hub and provide a 'projectId' with 'axeAccountURL'.");
120
- axeDevTools = [AxeDevTools loginWithAPIKey:apiKey
121
- toServer:axeServiceUrl
122
- error:&loginError];
123
-
124
- hasUploadSession = NO;
125
- }
126
- } else { // else, follow walnut path
127
- if (axeUploadResults && projectId.length == 0) {
128
- if (axeAccountURL.length > 0) {
129
- // Dev Hub was named but no project was given, so results would have
130
- // nowhere to land.
131
- return FBResponseWithObject(@{ @"axeError": @"'projectId' is required in order to start a session when 'axeUploadResults' is true. Please provide your project ID from Axe Developer Hub, or set 'axeUploadResults' to false to keep results local." });
132
- }
133
-
134
- // Unlike Dev Hub, the mobile dashboard accepts uploads without a projectId,
135
- // so this path keeps working until it is decommissioned.
136
- NSLog(@"[axe-devtools] DEPRECATION: starting a session without a 'projectId' posts to the mobile dashboard, which is being decommissioned. Please provide your project ID from Axe Developer Hub, or set 'axeUploadResults' to false to keep results local.");
137
- axeDevTools = [AxeDevTools loginWithAPIKey:apiKey
138
- toServer:axeServiceUrl
139
- error:&loginError];
140
-
141
- // Uploading stays on, but no Dev Hub session is waiting on this data.
142
- hasUploadSession = NO;
143
- } else {
144
- axeDevTools = [AxeDevTools startScanSessionWithApiKey:apiKey
145
- axeAccountUrl:axeAccountURL
146
- projectId:(projectId.length > 0 ? projectId : nil)
147
- axeUploadResults:axeUploadResults
148
- error:&loginError];
149
-
150
- hasUploadSession = (axeUploadResults && projectId.length > 0);
151
- }
152
- }
199
+ instance = [AxeDevTools startScanSessionWithApiKey:apiKey
200
+ axeAccountUrl:axeAccountURL
201
+ projectId:(projectId.length > 0 ? projectId : nil)
202
+ axeUploadResults:axeUploadResults
203
+ error:&loginError];
204
+
205
+ sessionUploads = (axeUploadResults && projectId.length > 0);
153
206
  }
154
207
  #else
155
- axeDevTools = [AxeDevTools loginWithLicenseKey:licenseKey
156
- error:&loginError];
208
+ instance = [AxeDevTools loginWithLicenseKey:licenseKey
209
+ error:&loginError];
157
210
  #endif
158
211
 
159
212
  if (loginError) {
@@ -161,6 +214,10 @@ static NSString *credentialKey;
161
214
  return FBResponseWithObject(@{ @"axeError" : loginError.localizedDescription});
162
215
  }
163
216
 
217
+ [self applyIgnoreSettings:settings toInstance:instance];
218
+
219
+ [self setSharedAxeDevTools:instance];
220
+ [self setSharedHasUploadSession:sessionUploads];
164
221
  [self setSharedUploadResults:axeUploadResults];
165
222
 
166
223
  #if AUTH
@@ -1,5 +1,5 @@
1
1
  //
2
- // AxeAuthCommands.m
2
+ // AxeAutoScanCommands.m
3
3
  // WebDriverAgent
4
4
  //
5
5
  // Created by Devanshu Chandra on 11/19/25.
@@ -49,7 +49,6 @@
49
49
 
50
50
  // optional properties with default values
51
51
  NSString *axeAccountURL = settings[@"axeAccountURL"] ?: @"";
52
- NSString *axeServiceUrl = settings[@"axeServerUrl"] ?: @"";
53
52
  BOOL uploadToDashboard = [settings[@"axeUploadResults"] ?: @YES boolValue];
54
53
 
55
54
  // optional properties if null will be handled appropriately by the framework
@@ -59,13 +58,8 @@
59
58
  NSError *enableError = nil;
60
59
 
61
60
  #if AUTH
62
- if (axeServiceUrl.length > 0) {
63
- NSLog(@"[axe-devtools] DEPRECATION: 'axeServerUrl' settings property is deprecated and will be removed in a future release. Please migrate to 'axeAccountURL'.");
64
- }
65
-
66
61
  [[AutoScanManager shared] enableWithBundleId:bundleId
67
62
  apiKey:apiKey
68
- axeServiceUrl:axeServiceUrl
69
63
  axeAccountUrl:axeAccountURL
70
64
  projectId:projectId
71
65
  uploadToDashboard:uploadToDashboard
@@ -34,160 +34,29 @@
34
34
 
35
35
  #pragma mark - Commands
36
36
 
37
- + (void)warnDeprecatedScanSettings:(NSDictionary *)settings
38
- {
39
- if (settings[@"apiKey"]) {
40
- NSLog(@"[axe-devtools] DEPRECATION: the 'apiKey' settings property is deprecated on the axeScan command and will be removed in a future release. Please pass it to the 'axeStartSession' command once at session start instead.");
41
- }
42
-
43
- if (settings[@"licenseKey"]) {
44
- NSLog(@"[axe-devtools] DEPRECATION: the 'licenseKey' settings property is deprecated on the axeScan command and will be removed in a future release. Please pass it to the 'axeStartSession' command once at session start instead.");
45
- }
46
-
47
- if (settings[@"axeAccountURL"]) {
48
- NSLog(@"[axe-devtools] DEPRECATION: the 'axeAccountURL' settings property is deprecated on the axeScan command and will be removed in a future release. Please pass it to the 'axeStartSession' command once at session start instead.");
49
- }
50
-
51
- if (settings[@"axeServiceUrl"]) {
52
- NSLog(@"[axe-devtools] DEPRECATION: the 'axeServiceUrl' settings property is deprecated on the axeScan command and will be removed in a future release. Please pass 'axeAccountURL' to the 'axeStartSession' command once at session start instead.");
53
- }
54
-
55
- if (settings[@"projectId"]) {
56
- NSLog(@"[axe-devtools] DEPRECATION: the 'projectId' settings property is deprecated on the axeScan command and will be removed in a future release. Please pass it to the 'axeStartSession' command once at session start instead.");
57
- }
58
-
59
- if (settings[@"uploadToDashboard"]) {
60
- NSLog(@"[axe-devtools] DEPRECATION: the 'uploadToDashboard' settings property is deprecated and will be removed after the October 2026 release when the mobile dashboard is decommissioned. Please set 'axeUploadResults' on the 'axeStartSession' command instead; uploading requires both flags to stay on, so this property still suppresses uploads on its own.");
61
- }
62
-
63
- if (settings[@"tags"]) {
64
- NSLog(@"[axe-devtools] DEPRECATION: the 'tags' settings property is deprecated and will be removed after the October 2026 release when the mobile dashboard is decommissioned. Tags only label dashboard uploads and have no effect on local results.");
65
- }
66
-
67
- if (settings[@"scanName"]) {
68
- NSLog(@"[axe-devtools] DEPRECATION: the 'scanName' settings property is deprecated and will be removed after the October 2026 release when the mobile dashboard is decommissioned. Scan names only label dashboard uploads and have no effect on local results.");
69
- }
70
-
71
- if (settings[@"ignoreRules"]) {
72
- NSLog(@"[axe-devtools] DEPRECATION: the 'ignoreRules' settings property is deprecated on the axeScan command and will be removed in a future release. A session-level replacement has not shipped yet, so please keep using it until one does.");
73
- }
74
-
75
- if (settings[@"ignoreExperimental"]) {
76
- NSLog(@"[axe-devtools] DEPRECATION: the 'ignoreExperimental' settings property is deprecated on the axeScan command and will be removed in a future release. A session-level replacement has not shipped yet, so please keep using it until one does.");
77
- }
78
- }
79
-
80
37
  + (id<FBResponsePayload>)handleAxeScanCommand:(FBRouteRequest *)request
81
38
  {
82
- // Warn before any validation so a caller tripping an unrelated error still learns
83
- // about the sunset. Covers both the authenticate-from-scan and existing-session
84
- // paths below, which each read these settings separately.
85
- [self warnDeprecatedScanSettings:request.arguments];
86
-
39
+ NSDictionary *settings = request.arguments;
40
+ NSString *bundleId = settings[@"bundleId"];
41
+ NSString *scanName = settings[@"scanName"] ?: @"";
87
42
  AxeDevTools *axeDevTools = [AxeAuthCommands sharedAxeDevTools];
88
- BOOL hasUploadSession = [AxeAuthCommands sharedHasUploadSession];
89
-
90
- // If the request provides credentials that differ from the ones used to
91
- // create the current singleton, invalidate it so re-authentication occurs.
92
- if (axeDevTools) {
93
- NSDictionary *incomingSettings = request.arguments;
94
- NSString *incomingCredential = nil;
95
43
 
96
- #if AUTH
97
- id rawToken = incomingSettings[@"accessToken"];
98
- if ([rawToken isKindOfClass:[NSString class]] && [rawToken length] > 0) {
99
- incomingCredential = rawToken;
100
- } else {
101
- id rawKey = incomingSettings[@"apiKey"];
102
- incomingCredential = [rawKey isKindOfClass:[NSString class]] ? rawKey : nil;
103
- }
104
- #else
105
- id rawKey = incomingSettings[@"licenseKey"];
106
- incomingCredential = [rawKey isKindOfClass:[NSString class]] ? rawKey : nil;
107
- #endif
108
- NSString *currentKey = [AxeAuthCommands sharedCredentialKey];
44
+ #if AUTH
45
+ // The MCP server's one-shot scan signs in with an access token here instead of calling
46
+ // 'axeStartSession'. A token that differs from the installed session's replaces it.
47
+ id rawToken = settings[@"accessToken"];
48
+ NSString *accessToken = [rawToken isKindOfClass:[NSString class]] ? rawToken : @"";
49
+ NSString *sessionToken = axeDevTools ? [AxeAuthCommands sharedCredentialKey] : nil;
50
+ BOOL isNewToken = accessToken.length > 0 && ![accessToken isEqualToString:sessionToken ?: @""];
51
+ if (isNewToken) {
52
+ [AxeAuthCommands setSharedAxeDevTools:nil];
53
+ [AxeAuthCommands setSharedCredentialKey:nil];
54
+ [AxeAuthCommands setSharedHasUploadSession:NO];
55
+ [AxeAuthCommands setSharedUploadResults:YES];
109
56
 
110
- if (incomingCredential != nil && ![incomingCredential isEqualToString:currentKey ?: @""]) {
111
- axeDevTools = nil;
112
- [AxeAuthCommands setSharedAxeDevTools:nil];
113
- [AxeAuthCommands setSharedCredentialKey:nil];
114
- [AxeAuthCommands setSharedHasUploadSession:NO];
115
- [AxeAuthCommands setSharedUploadResults:YES];
116
- }
117
- }
118
-
119
- // TODO: (October release) Remove this if block and any other auth/user-verification steps. Why?: All user verification (auth and no-auth) happens in the axeAuth command now.
120
- if (!axeDevTools) {
121
57
  NSError *loginError = nil;
122
- NSError *runScanError = nil;
123
- NSError *postResultError = nil;
124
-
125
- NSDictionary *settings = request.arguments;
126
-
127
- // required properties
128
- NSString *apiKey = settings[@"apiKey"];
129
- NSString *accessToken = settings[@"accessToken"] ?: @"";
130
- NSString *bundleId = settings[@"bundleId"];
131
- #if !AUTH
132
- NSString *licenseKey = settings[@"licenseKey"];
133
- #endif
134
-
135
- // optional properties with default values
136
58
  NSString *axeAccountURL = settings[@"axeAccountURL"] ?: @"";
137
- NSString *axeServiceUrl = settings[@"axeServiceUrl"] ?: @"";
138
- NSString *scanName = settings[@"scanName"] ?: @"";
139
- NSArray<NSString *> *tags = settings[@"tags"] ?: @[];
140
- NSArray<NSString *> *ignoreRules = settings[@"ignoreRules"] ?: @[];
141
- BOOL ignoreExperimental = [settings[@"ignoreExperimental"] ?: @NO boolValue];
142
- BOOL uploadToDashboard = [settings[@"uploadToDashboard"] ?: @YES boolValue];
143
- NSString *projectId = settings[@"projectId"] ?: @"";
144
-
145
- #if AUTH
146
- AxeDevToolsResultKey *axeResultKey;
147
-
148
- if (accessToken.length > 0) {
149
- // OAuth access token authentication (used by MCP server)
150
- axeDevTools = [AxeDevTools loginWithAccessToken:accessToken axeAccountUrl:axeAccountURL error:&loginError];
151
- uploadToDashboard = NO;
152
- } else {
153
- if (projectId.length > 0) {
154
- NSLog(@"[axe-devtools] DEPRECATION: 'projectId' settings property is deprecated in conjunction with the axeScan command and will be removed in a future release from the axeScan command. Please use 'axeStartSession' command to initialize a Dev Hub session using a 'projectId' and then call 'axeScan' command without API key to post to the same session.");
155
- }
156
-
157
- if (axeServiceUrl.length > 0) {
158
- NSLog(@"[axe-devtools] DEPRECATION: 'axeServiceUrl' settings property is deprecated and will be removed in a future release. Please migrate to 'axeAccountURL'.");
159
- }
160
-
161
- if (uploadToDashboard && axeAccountURL.length > 0 && projectId.length == 0) {
162
- return FBResponseWithObject(@{ @"axeError": @"'axeAccountURL' requires a 'projectId' in order to start a session. Please provide your project ID from Axe Developer Hub." });
163
- }
164
-
165
- if (uploadToDashboard == NO) {
166
- // uploadToDashboard is false: authenticate without creating a Dev Hub session.
167
- // An unpopulated session lingers as a "waiting for data" zombie in Axe Developer
168
- // Hub, so we validate credentials only and scan locally instead. See #355.
169
- if (axeAccountURL.length == 0 && axeServiceUrl.length > 0) {
170
- // serviceUrl-only creds can't use authenticate(); validate via the mobile
171
- // service instead — no session created (#361). Remove at decommission.
172
- axeDevTools = [AxeDevTools loginWithAPIKey:apiKey toServer:axeServiceUrl error:&loginError];
173
- } else {
174
- axeDevTools = [AxeDevTools authenticateWithApiKey:apiKey axeAccountUrl:axeAccountURL error:&loginError];
175
- }
176
- } else if (axeAccountURL.length == 0 && projectId.length > 0 && axeServiceUrl.length > 0) {
177
- NSLog(@"[axe-devtools] DEPRECATION: The old Mobile Service is being deprecated. Please migrate to Axe Developer Hub and provide a 'projectId' with 'axeAccountURL'.");
178
- axeDevTools = [AxeDevTools startSessionWithApiKey:apiKey url:axeServiceUrl projectId:projectId error:&loginError];
179
- } else if (projectId.length > 0) {
180
- axeDevTools = [AxeDevTools startScanSessionWithApiKey:apiKey axeAccountUrl:axeAccountURL projectId:projectId error:&loginError];
181
- } else {
182
- NSLog(@"[axe-devtools] DEPRECATION: The mobile dashboard is being deprecated. Please set up your project in Axe Developer Hub and provide a 'projectId' with 'axeAccountURL'.");
183
- axeDevTools = [AxeDevTools loginWithAPIKey:apiKey toServer:axeServiceUrl error:&loginError];
184
- }
185
- }
186
-
187
- #else
188
- axeDevTools = [AxeDevTools loginWithLicenseKey:licenseKey error:&loginError];
189
- uploadToDashboard = NO;
190
- #endif
59
+ axeDevTools = [AxeDevTools loginWithAccessToken:accessToken axeAccountUrl:axeAccountURL error:&loginError];
191
60
 
192
61
  if (loginError) {
193
62
  NSLog(@"Error logging in: %@", loginError.localizedDescription);
@@ -195,192 +64,65 @@
195
64
  }
196
65
 
197
66
  [AxeAuthCommands setSharedAxeDevTools:axeDevTools];
198
- [AxeAuthCommands setSharedHasUploadSession:(uploadToDashboard && projectId.length > 0)];
199
- [AxeAuthCommands setSharedUploadResults:uploadToDashboard];
200
- #if AUTH
201
- [AxeAuthCommands setSharedCredentialKey:(accessToken.length > 0 ? accessToken : apiKey)];
202
- #else
203
- [AxeAuthCommands setSharedCredentialKey:licenseKey];
204
- #endif
205
-
206
- [[axeDevTools configuration] ignoreWithRules:ignoreRules :YES];
207
-
208
- if (ignoreExperimental) {
209
- [[axeDevTools configuration] ignoreExperimental];
210
- }
211
-
212
-
213
- AxeResult *axeResult = [axeDevTools runOnBundleIdentifier:bundleId error:&runScanError];
214
-
215
- if (runScanError) {
216
- NSLog(@"Error on running scan: %@", runScanError.localizedDescription);
217
- return FBResponseWithObject(@{ @"axeError" : runScanError.localizedDescription});
218
- }
219
-
220
- if (uploadToDashboard) {
221
- #if AUTH
222
- axeResultKey = [axeDevTools postResult:axeResult
223
- withTags:tags
224
- withScanName:scanName
225
- error:&postResultError];
226
- #endif
227
- } else {
228
- axeResult.tags = tags;
229
- axeResult.scanName = scanName;
230
- }
231
-
232
- if (postResultError) {
233
- NSLog(@"Error sending result: %@", postResultError.localizedDescription);
234
- return FBResponseWithObject(@{ @"axeError" : postResultError.localizedDescription});
235
- }
236
-
237
-
238
- id jsonLocalScanResult = nil;
239
-
240
- @try {
241
- JSONHelper *helper = [[JSONHelper alloc] init];
242
-
243
- NSError *jsonError = nil;
244
- NSData *jsonData = [helper jsonDataFrom:axeResult error:&jsonError];
245
-
246
- if (jsonError) @throw [NSException exceptionWithName:@"" reason:jsonError.localizedDescription userInfo:nil];
247
-
248
- NSError *jsonSerializationError = nil;
249
- jsonLocalScanResult = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&jsonSerializationError];
250
-
251
- if (jsonSerializationError) @throw [NSException exceptionWithName:@"" reason:jsonSerializationError.localizedDescription userInfo:nil];
252
-
253
- #if AUTH
254
- if (uploadToDashboard) {
255
- NSMutableDictionary *axeResultWithAxeResultKey = [NSMutableDictionary dictionaryWithDictionary:jsonLocalScanResult];
256
-
257
- axeResultWithAxeResultKey[@"axeResultKey"] = @{
258
- @"userId": axeResultKey.userId ?: @"",
259
- @"packageName": axeResultKey.packageName ?: @"",
260
- @"resultId": axeResultKey.resultId ?: @"",
261
- @"uuid": axeResultKey.uuid ?: @""
262
- };
263
-
264
- return FBResponseWithObject(axeResultWithAxeResultKey);
265
- }
266
- #endif
267
- } @catch(NSException *e) {
268
- NSString *errorMessage = [NSString stringWithFormat:@"Failed to process local scan result into json format, %@", e.reason];
269
- return FBResponseWithObject(@{@"axeError": errorMessage });
270
- }
271
-
272
- return FBResponseWithObject(jsonLocalScanResult);
273
- } else {
274
- // Handles the scenario where someone is already authenticated through the axeStartSession command
275
- NSError *runScanError = nil;
276
- NSError *postResultError = nil;
277
-
278
- NSDictionary *settings = request.arguments;
279
-
280
- // required properties
281
- NSString *bundleId = settings[@"bundleId"];
282
- #if !AUTH
283
- NSString *licenseKey = settings[@"licenseKey"];
284
- #endif
285
-
286
- // optional properties with default values
287
- NSString *scanName = settings[@"scanName"] ?: @"";
288
- NSArray<NSString *> *tags = settings[@"tags"] ?: @[];
289
- NSArray<NSString *> *ignoreRules = settings[@"ignoreRules"] ?: @[];
290
- BOOL ignoreExperimental = [settings[@"ignoreExperimental"] ?: @NO boolValue];
291
- BOOL uploadToDashboard = [settings[@"uploadToDashboard"] ?: @YES boolValue];
292
-
293
- #if AUTH
294
- AxeDevToolsResultKey *axeResultKey;
67
+ [AxeAuthCommands setSharedUploadResults:NO];
68
+ [AxeAuthCommands setSharedCredentialKey:accessToken];
69
+ }
70
+ #endif
295
71
 
296
- // The session's choice wins over whatever this request asked for.
297
- if (![AxeAuthCommands sharedUploadResults]) {
298
- // An absent 'uploadToDashboard' defaults to YES and carries no intent, so the
299
- // nil check keeps this off every ordinary local-only scan.
300
- if (settings[@"uploadToDashboard"] != nil && uploadToDashboard) {
301
- NSLog(@"[axe-devtools] 'uploadToDashboard' was ignored: this session does not upload results, so the scan is being kept local. Sessions started with 'axeUploadResults' false, and sessions authenticated with an 'accessToken', never upload.");
302
- }
72
+ if (!axeDevTools) {
73
+ return FBResponseWithObject(@{ @"axeError" : @"No axe session is active. Call 'axeStartSession' with your credentials before 'axeScan'." });
74
+ }
303
75
 
304
- uploadToDashboard = NO;
305
- }
306
- #else
307
- uploadToDashboard = NO;
308
- #endif
76
+ #if AUTH
77
+ BOOL uploadResults = [AxeAuthCommands sharedUploadResults];
78
+ #else
79
+ BOOL uploadResults = NO;
80
+ #endif
309
81
 
310
- [[axeDevTools configuration] ignoreWithRules:ignoreRules :YES];
82
+ NSError *runScanError = nil;
83
+ AxeResult *axeResult = [axeDevTools runOnBundleIdentifier:bundleId error:&runScanError];
311
84
 
312
- if (ignoreExperimental) {
313
- [[axeDevTools configuration] ignoreExperimental];
314
- }
85
+ if (runScanError) {
86
+ NSLog(@"Error on running scan: %@", runScanError.localizedDescription);
87
+ return FBResponseWithObject(@{ @"axeError" : runScanError.localizedDescription});
88
+ }
315
89
 
90
+ if (uploadResults) {
316
91
  #if AUTH
317
- if (hasUploadSession == YES && uploadToDashboard == NO) {
318
- NSLog(@"Error on running scan: %@", @"The uploadToDashboard is set to false and projectId is set. Scan should be uploaded to show up in Axe Developer Hub.");
319
- return FBResponseWithObject(@{ @"axeError" : @"The uploadToDashboard is set to false and projectId is set. Scan should be uploaded to show up in Axe Developer Hub."});
320
- }
321
- #endif
322
-
323
- AxeResult *axeResult = [axeDevTools runOnBundleIdentifier:bundleId error:&runScanError];
324
-
325
- if (runScanError) {
326
- NSLog(@"Error on running scan: %@", runScanError.localizedDescription);
327
- return FBResponseWithObject(@{ @"axeError" : runScanError.localizedDescription});
328
- }
329
-
330
- if (uploadToDashboard) {
331
- #if AUTH
332
- axeResultKey = [axeDevTools postResult:axeResult
333
- withTags:tags
334
- withScanName:scanName
335
- error:&postResultError];
336
- #endif
337
- } else {
338
- axeResult.tags = tags;
339
- axeResult.scanName = scanName;
340
- }
92
+ NSError *postResultError = nil;
93
+ [axeDevTools postResult:axeResult
94
+ withScanName:scanName
95
+ error:&postResultError];
341
96
 
342
97
  if (postResultError) {
343
98
  NSLog(@"Error sending result: %@", postResultError.localizedDescription);
344
99
  return FBResponseWithObject(@{ @"axeError" : postResultError.localizedDescription});
345
100
  }
101
+ #endif
102
+ } else {
103
+ axeResult.scanName = scanName;
104
+ }
346
105
 
106
+ id jsonLocalScanResult = nil;
347
107
 
348
- id jsonLocalScanResult = nil;
349
-
350
- @try {
351
- JSONHelper *helper = [[JSONHelper alloc] init];
352
-
353
- NSError *jsonError = nil;
354
- NSData *jsonData = [helper jsonDataFrom:axeResult error:&jsonError];
355
-
356
- if (jsonError) @throw [NSException exceptionWithName:@"" reason:jsonError.localizedDescription userInfo:nil];
357
-
358
- NSError *jsonSerializationError = nil;
359
- jsonLocalScanResult = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&jsonSerializationError];
360
-
361
- if (jsonSerializationError) @throw [NSException exceptionWithName:@"" reason:jsonSerializationError.localizedDescription userInfo:nil];
108
+ @try {
109
+ JSONHelper *helper = [[JSONHelper alloc] init];
362
110
 
363
- #if AUTH
364
- if (uploadToDashboard) {
365
- NSMutableDictionary *axeResultWithAxeResultKey = [NSMutableDictionary dictionaryWithDictionary:jsonLocalScanResult];
111
+ NSError *jsonError = nil;
112
+ NSData *jsonData = [helper jsonDataFrom:axeResult error:&jsonError];
366
113
 
367
- axeResultWithAxeResultKey[@"axeResultKey"] = @{
368
- @"userId": axeResultKey.userId ?: @"",
369
- @"packageName": axeResultKey.packageName ?: @"",
370
- @"resultId": axeResultKey.resultId ?: @"",
371
- @"uuid": axeResultKey.uuid ?: @""
372
- };
114
+ if (jsonError) @throw [NSException exceptionWithName:@"" reason:jsonError.localizedDescription userInfo:nil];
373
115
 
374
- return FBResponseWithObject(axeResultWithAxeResultKey);
375
- }
376
- #endif
377
- } @catch(NSException *e) {
378
- NSString *errorMessage = [NSString stringWithFormat:@"Failed to process local scan result into json format, %@", e.reason];
379
- return FBResponseWithObject(@{@"axeError": errorMessage });
380
- }
116
+ NSError *jsonSerializationError = nil;
117
+ jsonLocalScanResult = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&jsonSerializationError];
381
118
 
382
- return FBResponseWithObject(jsonLocalScanResult);
119
+ if (jsonSerializationError) @throw [NSException exceptionWithName:@"" reason:jsonSerializationError.localizedDescription userInfo:nil];
120
+ } @catch(NSException *e) {
121
+ NSString *errorMessage = [NSString stringWithFormat:@"Failed to process local scan result into json format, %@", e.reason];
122
+ return FBResponseWithObject(@{@"axeError": errorMessage });
383
123
  }
124
+
125
+ return FBResponseWithObject(jsonLocalScanResult);
384
126
  }
385
127
 
386
128
  @end