Skip to content

Commit

Permalink
[milestone/11.9.1] Release 11.9.1 (#94)
Browse files Browse the repository at this point in the history
- OCHostSimulator: add auth-race-condition host simulator, to test handling of race conditions in Authorization
- OCCoreNetworkMonitorSignalProvider: add logging
- OCNetworkMonitor: add logging
- OCAuthenticationMethodOAuth2/OIDC: no longer treat network errors during token refresh as permanently failed refresh
  • Loading branch information
felix-schwarz authored Mar 29, 2022
1 parent a98b3e6 commit d2fa235
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 11.9.1 version
- OCAuthenticationMethodOAuth2/OIDC: no longer treat network errors during token refresh as permanently failed refresh
- OCHostSimulator: add auth-race-condition host simulator, to test handling of race conditions in Authorization
- OCNetworkMonitor / OCCoreNetworkMonitorSignalProvider: add logging

## 11.9 version
- Authentication: new type OCAuthenticationDataID
- an ID that's unique for every OCBookmark.authenticationData and changes when the authenticationData is changed
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ Note: since `OCEventTarget` handles the resolution and actual delivery of the ev
This project is currently licensed under GPL v3.
We do provide support as well as an option for a dual-licensing as part of our ownCloud Enterprise subscriptions. Please contact [email protected] for more information.


11 changes: 8 additions & 3 deletions ownCloudSDK/Authentication/OCAuthenticationMethodOAuth2.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#import "OCMacros.h"
#import "OCLockManager.h"
#import "OCLockRequest.h"
#import "NSError+OCNetworkFailure.h"

#pragma mark - Internal OA2 keys
typedef NSString* OA2DictKeyPath;
Expand Down Expand Up @@ -740,9 +741,13 @@ - (void)__refreshTokenForConnection:(OCConnection *)connection availabilityHandl
else
{
// Did not receive update
[self willChangeValueForKey:@"authenticationDataKnownInvalidDate"];
self->_authenticationDataKnownInvalidDate = [NSDate new];
[self didChangeValueForKey:@"authenticationDataKnownInvalidDate"];
if ((error == nil) || ((error != nil) && !error.isNetworkFailureError))
{
// Not a network failure, either, so handle as actual error refreshing the token
[self willChangeValueForKey:@"authenticationDataKnownInvalidDate"];
self->_authenticationDataKnownInvalidDate = [NSDate new];
[self didChangeValueForKey:@"authenticationDataKnownInvalidDate"];
}
}

if (self->_receivedUnauthorizedResponse)
Expand Down
2 changes: 2 additions & 0 deletions ownCloudSDK/Cellular/OCNetworkMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ - (void)setActive:(BOOL)active

weakSelf.isExpensive = nw_path_is_expensive(path); // Cellular data or tethered connection

OCWTLogDebug(@[@"NetworkAvailability"], @"Network availability changed to available=%d, isCellularConnection=%d, isWifiOrEthernetConnection=%d", weakSelf.networkAvailable, weakSelf.isCellularConnection, weakSelf.isWifiOrEthernetConnection);

// Post local notification
[NSNotificationCenter.defaultCenter postNotificationName:OCNetworkMonitorStatusChangedNotification object:self];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ - (void)_updateState:(nullable NSNotification *)notification

self.shortDescription = shortDescription;
self.state = state;

OCTLogDebug(@[@"NetworkAvailability"], @"Reachable signal changed to %lu (%@)", (unsigned long)state, shortDescription);
}
}

Expand Down
48 changes: 48 additions & 0 deletions ownCloudSDK/Host Simulator/OCHostSimulator+BuiltIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
static OCHostSimulationIdentifier OCHostSimulationIdentifierSimpleAPM = @"simple-apm";
static OCHostSimulationIdentifier OCHostSimulationIdentifierRecoveringAPM = @"recovering-apm";
static OCHostSimulationIdentifier OCHostSimulationIdentifierWebFinger = @"web-finger";
static OCHostSimulationIdentifier OCHostSimulationIdentifierAuthRaceCondition = @"auth-race-condition";

@implementation OCHostSimulator (BuiltIn)

Expand Down Expand Up @@ -76,6 +77,13 @@ + (void)load
} provider:^id<OCConnectionHostSimulator> _Nullable(OCExtension * _Nonnull extension, OCExtensionContext * _Nonnull context, NSError * _Nullable __autoreleasing * _Nullable error) {
return ([self webFingerSimulator]);
}]];

// AuthRaceCondition
[OCExtensionManager.sharedExtensionManager addExtension:[OCExtension hostSimulationExtensionWithIdentifier:OCHostSimulationIdentifierAuthRaceCondition locations:@[ OCExtensionLocationIdentifierAllCores, OCExtensionLocationIdentifierAccountSetup ] metadata:@{
OCExtensionMetadataKeyDescription : @"Responds to all .well-known/webfinger requests with server-instance responses."
} provider:^id<OCConnectionHostSimulator> _Nullable(OCExtension * _Nonnull extension, OCExtensionContext * _Nonnull context, NSError * _Nullable __autoreleasing * _Nullable error) {
return ([self authRaceConditionSimulator]);
}]];
}

+ (OCHostSimulator *)hostSimulatorWithRequestHandler:(OCHostSimulatorRequestHandler)requestHandler
Expand Down Expand Up @@ -272,4 +280,44 @@ + (instancetype)webFingerSimulator
return (hostSimulator);
}

#pragma mark - Auth Race Condition Simulator
+ (instancetype)authRaceConditionSimulator
{
OCHostSimulator *hostSimulator;

NSMutableSet<NSString *> *disruptedAuthHeaders = [NSMutableSet new];
__block NSUInteger requestCounter = 0;

hostSimulator = [OCHostSimulator new];
hostSimulator.requestHandler = ^BOOL(OCConnection *connection, OCHTTPRequest *request, OCHostSimulatorResponseHandler responseHandler) {
NSString *authorizationHeader = request.headerFields[@"Authorization"];
NSString *invalidAuthContent = @"INVALID";

if ((authorizationHeader != nil) && ![authorizationHeader isEqual:invalidAuthContent] && ![disruptedAuthHeaders containsObject:authorizationHeader])
{
requestCounter++;

if (requestCounter < 5)
{
request.headerFields[@"Authorization"] = invalidAuthContent;
request.authenticationDataID = invalidAuthContent;

responseHandler(nil, [OCHostSimulatorResponse responseWithURL:request.url statusCode:OCHTTPStatusCodeUNAUTHORIZED headers:nil contentType:@"text/html" bodyData:nil]);

return (YES);
}
else
{
[disruptedAuthHeaders addObject:authorizationHeader];
}
}

return (NO);
};

hostSimulator.unroutableRequestHandler = nil;

return (hostSimulator);
}

@end

0 comments on commit d2fa235

Please sign in to comment.