Skip to content

Commit d4ec660

Browse files
committed
Add unit tests. Validate expected flight value before trying to convert.
1 parent ef4b4c6 commit d4ec660

File tree

5 files changed

+141
-1
lines changed

5 files changed

+141
-1
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,8 @@
18001800
B48FC02F2D726A52007B80DB /* MSIDBrokerFlightProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = B48FC02E2D726A48007B80DB /* MSIDBrokerFlightProvider.h */; };
18011801
B48FC0312D726A66007B80DB /* MSIDBrokerFlightProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = B48FC0302D726A64007B80DB /* MSIDBrokerFlightProvider.m */; };
18021802
B48FC0322D726A66007B80DB /* MSIDBrokerFlightProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = B48FC0302D726A64007B80DB /* MSIDBrokerFlightProvider.m */; };
1803+
B48FC0622D7A90FA007B80DB /* MSIDBrokerFlightProviderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B48FC0612D7A90F4007B80DB /* MSIDBrokerFlightProviderTests.m */; };
1804+
B48FC0632D7A90FA007B80DB /* MSIDBrokerFlightProviderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B48FC0612D7A90F4007B80DB /* MSIDBrokerFlightProviderTests.m */; };
18031805
B49323912AD491C600E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = B493238F2AD4919400E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.h */; };
18041806
B49323922AD491CE00E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = B49323902AD491B900E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.m */; };
18051807
B49323932AD491CF00E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = B49323902AD491B900E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.m */; };
@@ -3248,6 +3250,7 @@
32483250
B443F0012AD6328700782168 /* MSIDBrokerOperationPasskeyCredentialRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBrokerOperationPasskeyCredentialRequest.m; sourceTree = "<group>"; };
32493251
B48FC02E2D726A48007B80DB /* MSIDBrokerFlightProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBrokerFlightProvider.h; sourceTree = "<group>"; };
32503252
B48FC0302D726A64007B80DB /* MSIDBrokerFlightProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBrokerFlightProvider.m; sourceTree = "<group>"; };
3253+
B48FC0612D7A90F4007B80DB /* MSIDBrokerFlightProviderTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBrokerFlightProviderTests.m; sourceTree = "<group>"; };
32513254
B493238F2AD4919400E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBrokerOperationPasskeyAssertionRequest.h; sourceTree = "<group>"; };
32523255
B49323902AD491B900E0CBC0 /* MSIDBrokerOperationPasskeyAssertionRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBrokerOperationPasskeyAssertionRequest.m; sourceTree = "<group>"; };
32533256
B49323942AD4DA0200E0CBC0 /* MSIDBrokerOperationGetPasskeyAssertionResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBrokerOperationGetPasskeyAssertionResponse.h; sourceTree = "<group>"; };
@@ -5616,6 +5619,7 @@
56165619
23419F59239739AF00EA78C5 /* MSIDBrokerOperationSilentTokenRequestTests.m */,
56175620
23419F5F23974C0D00EA78C5 /* MSIDBrokerOperationTokenRequestTests.m */,
56185621
23419F782399AD7500EA78C5 /* MSIDBrokerOperationTokenResponseTests.m */,
5622+
B48FC0612D7A90F4007B80DB /* MSIDBrokerFlightProviderTests.m */,
56195623
231CE9C91FE8D79A00E95D3E /* MSIDCacheItemJsonSerializerTests.m */,
56205624
B2DD4B2D20A8D7DE0047A66E /* MSIDCacheKeyTests.m */,
56215625
23B37D1D20CA098E0018722F /* MSIDCacheTests.m */,
@@ -6910,6 +6914,7 @@
69106914
B210F42E1FDDE6A5005A8F76 /* MSIDJsonObjectTests.m in Sources */,
69116915
B2E97FB32914CC4500AFD558 /* MSIDBrokerNativeAppOperationResponseTests.m in Sources */,
69126916
B29F7805213DFA5600D61FC8 /* MSIDErrorTests.m in Sources */,
6917+
B48FC0622D7A90FA007B80DB /* MSIDBrokerFlightProviderTests.m in Sources */,
69136918
60747FF82354F73000C5308F /* MSIDBrokerOperationGetAccountsResponseTests.m in Sources */,
69146919
B2DD5B97204756580084313F /* MSIDAccountTypeTests.m in Sources */,
69156920
B2936F4D20AA906C0050C585 /* MSIDLegacyTokenCacheItemTests.m in Sources */,
@@ -7541,6 +7546,7 @@
75417546
B2561225217EA97000999876 /* MSIDB2COauth2FactoryTests.m in Sources */,
75427547
B2BE926221A25A8600F5AB8C /* MSIDInteractiveControllerIntegrationTests.m in Sources */,
75437548
B2BE923521A0F80100F5AB8C /* MSIDLegacyTokenRequestProviderTests.m in Sources */,
7549+
B48FC0632D7A90FA007B80DB /* MSIDBrokerFlightProviderTests.m in Sources */,
75447550
23FB5C21225516FB002BF1EB /* MSIDClaimsRequestTests.m in Sources */,
75457551
E75DD02625D5E474007664A6 /* MSIDThrottlingServiceIntegrationTests.m in Sources */,
75467552
B286BA07238A110A007833AD /* MSIDOIDCSignoutRequestTests.m in Sources */,

IdentityCore/src/MSIDBrokerFlightProvider.m

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,31 @@ - (BOOL)boolForKey:(nonnull NSString *)flightKey
8080
{
8181
if (self.clientFlightsPayload)
8282
{
83-
return [self.clientFlightsPayload[flightKey] boolValue];
83+
id value = self.clientFlightsPayload[flightKey];
84+
85+
if ([value isKindOfClass:[NSNumber class]] || [value isKindOfClass:[NSString class]])
86+
{
87+
return [value boolValue];
88+
}
8489
}
8590

8691
return NO;
8792
}
8893

94+
- (nullable NSArray<NSString *> *)stringsForFlightKey:(nonnull NSString *)flightKey
95+
{
96+
if (self.clientFlightsPayload)
97+
{
98+
id value = self.clientFlightsPayload[flightKey];
99+
100+
if ([value isKindOfClass:[NSArray class]])
101+
{
102+
return value;
103+
}
104+
}
105+
106+
return nil;
107+
}
108+
109+
89110
@end

IdentityCore/src/MSIDFlightManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
3030
@protocol MSIDFlightManagerInterface <NSObject>
3131

3232
- (BOOL)boolForKey:(NSString *)flightKey;
33+
- (nullable NSArray<NSString *> *)stringsForFlightKey:(NSString *)key;
34+
3335

3436
@end
3537

IdentityCore/src/MSIDFlightManager.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ - (BOOL)boolForKey:(nonnull NSString *)flightKey
4747
return NO;
4848
}
4949

50+
- (nullable NSArray<NSString *> *)stringsForFlightKey:(nonnull NSString *)flightKey
51+
{
52+
if (self.flightProvider) { return [self.flightProvider stringsForFlightKey:flightKey]; }
53+
54+
return nil;
55+
}
56+
57+
5058
@end
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
#import <XCTest/XCTest.h>
26+
#import "MSIDBrokerFlightProvider.h"
27+
28+
@interface MSIDBrokerFlightProviderTests : XCTestCase
29+
30+
@end
31+
32+
@implementation MSIDBrokerFlightProviderTests
33+
34+
- (void)testInitWithBase64EncodedFlightsPayload_whenNilOrEmptyPayload_shouldReturnNil
35+
{
36+
NSString *flightsPayload = nil;
37+
MSIDBrokerFlightProvider *flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
38+
39+
XCTAssertNil(flightProvider);
40+
41+
flightsPayload = @"";
42+
flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
43+
44+
XCTAssertNil(flightProvider);
45+
}
46+
47+
- (void)testInitWithBase64EncodedFlightsPayload_whenInvalidPayload_shouldReturnNil
48+
{
49+
NSString *flightsPayload = @"invalid_payload";
50+
MSIDBrokerFlightProvider *flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
51+
52+
XCTAssertNil(flightProvider);
53+
}
54+
55+
- (void)testInitWithBase64EncodedFlightsPayload_whenNotDictionaryPayload_shouldReturnNil
56+
{
57+
NSString *flightsPayload = @"bm90IGEgdmFsaWQgZGljdGlvbmFyeQ";
58+
MSIDBrokerFlightProvider *flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
59+
60+
XCTAssertNil(flightProvider);
61+
}
62+
63+
- (void)testInitWithBase64EncodedFlightsPayload_whenBoolFlight_shouldReadValue
64+
{
65+
NSString *flightsPayload = @"eyJmbGlnaHQxIjp0cnVlLCJmbGlnaHQyIjpbInRlbmFudDEiLCJ0ZW5hbnQyIl19";
66+
MSIDBrokerFlightProvider *flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
67+
68+
XCTAssertNotNil(flightProvider);
69+
XCTAssertTrue([flightProvider boolForKey:@"flight1"]);
70+
}
71+
72+
- (void)testInitWithBase64EncodedFlightsPayload_whenNotBoolFlight_shouldReturnFalse
73+
{
74+
NSString *flightsPayload = @"eyJmbGlnaHQxIjp0cnVlLCJmbGlnaHQyIjpbInRlbmFudDEiLCJ0ZW5hbnQyIl19";
75+
MSIDBrokerFlightProvider *flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
76+
77+
XCTAssertNotNil(flightProvider);
78+
XCTAssertFalse([flightProvider boolForKey:@"flight2"]);
79+
}
80+
81+
- (void)testInitWithBase64EncodedFlightsPayload_whenStringListFlight_shouldReadValues
82+
{
83+
NSString *flightsPayload = @"eyJmbGlnaHQxIjp0cnVlLCJmbGlnaHQyIjpbInRlbmFudDEiLCJ0ZW5hbnQyIl19";
84+
MSIDBrokerFlightProvider *flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
85+
86+
NSArray *strings = [flightProvider stringsForFlightKey:@"flight2"];
87+
88+
XCTAssertNotNil(flightProvider);
89+
XCTAssertEqual(strings.count, 2);
90+
}
91+
92+
- (void)testInitWithBase64EncodedFlightsPayload_whenNotStringListFlight_shouldReturnNil
93+
{
94+
NSString *flightsPayload = @"eyJmbGlnaHQxIjp0cnVlLCJmbGlnaHQyIjpbInRlbmFudDEiLCJ0ZW5hbnQyIl19";
95+
MSIDBrokerFlightProvider *flightProvider = [[MSIDBrokerFlightProvider alloc] initWithBase64EncodedFlightsPayload:flightsPayload];
96+
97+
NSArray *strings = [flightProvider stringsForFlightKey:@"flight1"];
98+
99+
XCTAssertNotNil(flightProvider);
100+
XCTAssertEqual(strings.count, 0);
101+
}
102+
103+
@end

0 commit comments

Comments
 (0)