Skip to content

Commit 30c85a1

Browse files
chore: fix aswebauthenticationsession issue for automated tests
1 parent 86bdfd3 commit 30c85a1

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Source/Immutable/Private/Immutable/Mac/ImmutableMac.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
#include "Immutable/ImmutablePassport.h"
33
#include "Immutable/ImmutableSubsystem.h"
44
#include "Engine/GameEngine.h"
5+
#include "Misc/AutomationTest.h"
56

67
#if WITH_EDITOR
78
#include "Editor.h"
89
#endif
910

11+
#import <AppKit/NSWorkspace.h>
12+
1013
ASWebAuthenticationSession *_authSession;
1114

15+
// Remove the global automation mode variable
16+
static NSString* _pendingRedirectScheme = nil;
17+
1218
@implementation ImmutableMac
1319

1420
- (instancetype)init {
@@ -67,6 +73,13 @@ ASWebAuthenticationSession *_authSession;
6773
}
6874

6975
- (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri {
76+
// For automation, use the browser-based method
77+
if (GIsAutomationTesting) {
78+
NSLog(@"Using automation mode for authentication (GIsAutomationTesting is true)");
79+
[self launchUrlInBrowser:url forRedirectUri:redirectUri];
80+
return;
81+
}
82+
7083
if (@available(macOS 10.15, *)) {
7184
NSURL *URL =
7285
[NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
@@ -104,6 +117,43 @@ ASWebAuthenticationSession *_authSession;
104117
}
105118
}
106119

120+
- (void)launchUrlInBrowser:(const char *)url forRedirectUri:(const char *)redirectUri {
121+
// Add redundant check to ensure this only runs for automated testing
122+
if (!GIsAutomationTesting) {
123+
return;
124+
}
125+
126+
// Create URL object
127+
NSURL *URL = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:url]];
128+
129+
// Extract the callback scheme from redirect URI
130+
NSString *redirectUriString = [[NSString alloc] initWithUTF8String:redirectUri];
131+
NSString *callbackURLScheme = [[redirectUriString componentsSeparatedByString:@":"] objectAtIndex:0];
132+
133+
// Store the redirect scheme for use when handling the callback
134+
_pendingRedirectScheme = callbackURLScheme;
135+
136+
// Register for custom URL scheme notifications (will need to be implemented in AppDelegate)
137+
[[NSNotificationCenter defaultCenter] addObserverForName:@"ImmutableCustomURLSchemeCallback"
138+
object:nil
139+
queue:[NSOperationQueue mainQueue]
140+
usingBlock:^(NSNotification *notification) {
141+
if (notification.userInfo) {
142+
NSString *callbackURLString = notification.userInfo[@"url"];
143+
if (callbackURLString) {
144+
UImmutablePassport* passport = [ImmutableMac getPassport];
145+
if (passport) {
146+
passport->HandleDeepLink(callbackURLString);
147+
}
148+
}
149+
}
150+
}];
151+
152+
// Open URL in default browser
153+
[[NSWorkspace sharedWorkspace] openURL:URL];
154+
NSLog(@"Opened URL in browser for automation: %@", URL);
155+
}
156+
107157
- (ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:
108158
(ASWebAuthenticationSession *)session API_AVAILABLE(macos(10.15)) {
109159
return [[[NSApplication sharedApplication] windows] firstObject];

Source/Immutable/Private/Immutable/Mac/ImmutableMac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
: NSObject <ASWebAuthenticationPresentationContextProviding>
88
+ (ImmutableMac *)instance;
99
- (void)launchUrl:(const char *)url forRedirectUri:(const char *)redirectUri;
10+
- (void)launchUrlInBrowser:(const char *)url forRedirectUri:(const char *)redirectUri;
1011
@end

0 commit comments

Comments
 (0)