Skip to content

Commit e1fbde9

Browse files
[Remove IID] Move some token unit tests from IID to Messaging (#7294)
1 parent 3090073 commit e1fbde9

File tree

13 files changed

+622
-57
lines changed

13 files changed

+622
-57
lines changed

Firebase/CoreDiagnostics/FIRCDLibrary/FIRCoreDiagnostics.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
#ifdef FIREBASE_BUILD_ZIP_FILE
3939
static BOOL kUsingZipFile = YES;
40-
#else // FIREBASE_BUILD_ZIP_FILE
40+
#else // FIREBASE_BUILD_ZIP_FILE
4141
static BOOL kUsingZipFile = NO;
4242
#endif // FIREBASE_BUILD_ZIP_FILE
4343

FirebaseDynamicLinks/Sources/Logging/FDLLogging.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#if __LP64__ // 64-bit
3131
NSString *const FDLMessageCodeIntegerFormat = @"%06ld";
32-
#else // 32-bit
32+
#else // 32-bit
3333
NSString *const FDLMessageCodeIntegerFormat = @"%06d";
3434
#endif // #if __LP64__
3535

FirebaseMessaging/Sources/Token/FIRMessagingAuthKeyChain.m renamed to FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeyChain.h"
17+
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.h"
1818
#import "FirebaseMessaging/Sources/FIRMessagingLogger.h"
1919
#import "FirebaseMessaging/Sources/Token/FIRMessagingKeychain.h"
2020

FirebaseMessaging/Sources/Token/FIRMessagingCheckinStore.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,6 @@ extern NSString *const kFIRMessagingCheckinKeychainService;
2828
*/
2929
@interface FIRMessagingCheckinStore : NSObject
3030

31-
/**
32-
* Designated Initializer. Initialize a checkin store with the given backup excluded
33-
* plist filename.
34-
*
35-
* @param checkinFilename The backup excluded plist filename to persist checkin
36-
* preferences.
37-
*
38-
* @param subDirectoryName Sub-directory in standard directory where we write
39-
* InstanceID plist.
40-
*
41-
* @return Store to persist checkin preferences.
42-
*/
43-
- (instancetype)initWithCheckinPlistFileName:(NSString *)checkinFilename
44-
subDirectoryName:(NSString *)subDirectoryName;
45-
46-
/**
47-
* Initialize a checkin store with the given backup excluded plist and keychain.
48-
*
49-
* @param plist The backup excluded plist to persist checkin preferences.
50-
* @param keychain The keychain used to persist checkin auth preferences.
51-
*
52-
* @return Store to persist checkin preferences.
53-
*/
54-
- (instancetype)initWithCheckinPlist:(FIRMessagingBackupExcludedPlist *)plist
55-
keychain:(FIRMessagingAuthKeychain *)keychain;
56-
5731
/**
5832
* Checks whether the backup excluded checkin preferences are present on the disk or not.
5933
*

FirebaseMessaging/Sources/Token/FIRMessagingCheckinStore.m

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717
#import "FirebaseMessaging/Sources/Token/FIRMessagingCheckinStore.h"
1818

1919
#import "FirebaseMessaging/Sources/FIRMessagingCode.h"
20+
#import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
2021
#import "FirebaseMessaging/Sources/FIRMessagingLogger.h"
2122
#import "FirebaseMessaging/Sources/FIRMessagingUtilities.h"
2223
#import "FirebaseMessaging/Sources/NSError+FIRMessaging.h"
23-
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeyChain.h"
24+
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.h"
2425
#import "FirebaseMessaging/Sources/Token/FIRMessagingBackupExcludedPlist.h"
2526
#import "FirebaseMessaging/Sources/Token/FIRMessagingCheckinPreferences.h"
2627
#import "FirebaseMessaging/Sources/Token/FIRMessagingCheckinService.h"
2728

29+
// NOTE: These values should be in sync with what InstanceID saves in as.
30+
static NSString *const kCheckinFileName = @"g-checkin";
2831
static NSString *const kFIRMessagingCheckinKeychainGeneric = @"com.google.iid";
29-
3032
NSString *const kFIRMessagingCheckinKeychainService = @"com.google.iid.checkin";
3133

3234
@interface FIRMessagingCheckinStore ()
@@ -42,23 +44,14 @@ @interface FIRMessagingCheckinStore ()
4244

4345
@implementation FIRMessagingCheckinStore
4446

45-
- (instancetype)initWithCheckinPlistFileName:(NSString *)checkinFilename
46-
subDirectoryName:(NSString *)subDirectoryName {
47-
FIRMessagingBackupExcludedPlist *plist =
48-
[[FIRMessagingBackupExcludedPlist alloc] initWithFileName:checkinFilename
49-
subDirectory:subDirectoryName];
50-
51-
FIRMessagingAuthKeychain *keychain =
52-
[[FIRMessagingAuthKeychain alloc] initWithIdentifier:kFIRMessagingCheckinKeychainGeneric];
53-
return [self initWithCheckinPlist:plist keychain:keychain];
54-
}
55-
56-
- (instancetype)initWithCheckinPlist:(FIRMessagingBackupExcludedPlist *)plist
57-
keychain:(FIRMessagingAuthKeychain *)keychain {
47+
- (instancetype)init {
5848
self = [super init];
5949
if (self) {
60-
_plist = plist;
61-
_keychain = keychain;
50+
_plist = [[FIRMessagingBackupExcludedPlist alloc]
51+
initWithFileName:kCheckinFileName
52+
subDirectory:kFIRMessagingInstanceIDSubDirectoryName];
53+
_keychain =
54+
[[FIRMessagingAuthKeychain alloc] initWithIdentifier:kFIRMessagingCheckinKeychainGeneric];
6255
}
6356
return self;
6457
}

FirebaseMessaging/Sources/Token/FIRMessagingTokenManager.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#import "FirebaseMessaging/Sources/FIRMessagingDefines.h"
2222
#import "FirebaseMessaging/Sources/FIRMessagingLogger.h"
2323
#import "FirebaseMessaging/Sources/NSError+FIRMessaging.h"
24-
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeyChain.h"
24+
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.h"
2525
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthService.h"
2626
#import "FirebaseMessaging/Sources/Token/FIRMessagingCheckinPreferences.h"
2727
#import "FirebaseMessaging/Sources/Token/FIRMessagingCheckinStore.h"
@@ -31,9 +31,6 @@
3131
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenOperation.h"
3232
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenStore.h"
3333

34-
// NOTE: These values should be in sync with what InstanceID saves in as.
35-
static NSString *const kCheckinFileName = @"g-checkin";
36-
3734
@interface FIRMessagingTokenManager () {
3835
FIRMessagingTokenStore *_tokenStore;
3936
FIRMessagingCheckinStore *_checkinStore;
@@ -54,9 +51,7 @@ - (instancetype)init {
5451
self = [super init];
5552
if (self) {
5653
_tokenStore = [[FIRMessagingTokenStore alloc] init];
57-
_checkinStore = [[FIRMessagingCheckinStore alloc]
58-
initWithCheckinPlistFileName:kCheckinFileName
59-
subDirectoryName:kFIRMessagingInstanceIDSubDirectoryName];
54+
_checkinStore = [[FIRMessagingCheckinStore alloc] init];
6055
_authService = [[FIRMessagingAuthService alloc] initWithCheckinStore:_checkinStore];
6156
[self resetCredentialsIfNeeded];
6257
[self configureTokenOperations];

FirebaseMessaging/Sources/Token/FIRMessagingTokenStore.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
2020
#import "FirebaseMessaging/Sources/FIRMessagingLogger.h"
2121
#import "FirebaseMessaging/Sources/FIRMessagingUtilities.h"
22-
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeyChain.h"
22+
#import "FirebaseMessaging/Sources/Token/FIRMessagingAuthKeychain.h"
2323
#import "FirebaseMessaging/Sources/Token/FIRMessagingTokenInfo.h"
2424

2525
static NSString *const kFIRMessagingTokenKeychainId = @"com.google.iid-tokens";
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
20+
#import "FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.h"
21+
22+
@interface FIRMessagingAPNSInfoTest : XCTestCase
23+
24+
@end
25+
26+
@implementation FIRMessagingAPNSInfoTest
27+
28+
- (void)testAPNSInfoCreationWithValidDictionary {
29+
NSDictionary *validDictionary = @{
30+
kFIRMessagingTokenOptionsAPNSKey : [@"tokenData" dataUsingEncoding:NSUTF8StringEncoding],
31+
kFIRMessagingTokenOptionsAPNSIsSandboxKey : @(YES)
32+
};
33+
FIRMessagingAPNSInfo *info =
34+
[[FIRMessagingAPNSInfo alloc] initWithTokenOptionsDictionary:validDictionary];
35+
XCTAssertNotNil(info);
36+
XCTAssertEqualObjects(info.deviceToken, validDictionary[kFIRMessagingTokenOptionsAPNSKey]);
37+
XCTAssertEqual(info.sandbox,
38+
[validDictionary[kFIRMessagingTokenOptionsAPNSIsSandboxKey] boolValue]);
39+
}
40+
41+
- (void)testAPNSInfoCreationWithInvalidDictionary {
42+
NSDictionary *validDictionary = @{};
43+
FIRMessagingAPNSInfo *info =
44+
[[FIRMessagingAPNSInfo alloc] initWithTokenOptionsDictionary:validDictionary];
45+
XCTAssertNil(info);
46+
}
47+
48+
- (void)testAPNSInfoCreationWithInvalidTokenFormat {
49+
// Token data stored as NSString instead of NSData
50+
NSDictionary *badDictionary = @{
51+
kFIRMessagingTokenOptionsAPNSKey : @"tokenDataAsString",
52+
kFIRMessagingTokenOptionsAPNSIsSandboxKey : @(YES)
53+
};
54+
FIRMessagingAPNSInfo *info =
55+
[[FIRMessagingAPNSInfo alloc] initWithTokenOptionsDictionary:badDictionary];
56+
XCTAssertNil(info);
57+
}
58+
59+
- (void)testAPNSInfoCreationWithInvalidSandboxFormat {
60+
// Sandbox key stored as NSString instead of NSNumber (bool)
61+
NSDictionary *validDictionary = @{
62+
kFIRMessagingTokenOptionsAPNSKey : [@"tokenData" dataUsingEncoding:NSUTF8StringEncoding],
63+
kFIRMessagingTokenOptionsAPNSIsSandboxKey : @"sandboxValueAsString"
64+
};
65+
FIRMessagingAPNSInfo *info =
66+
[[FIRMessagingAPNSInfo alloc] initWithTokenOptionsDictionary:validDictionary];
67+
XCTAssertNil(info);
68+
}
69+
70+
// Test that archiving a FIRMessagingAPNSInfo object and restoring it from the archive
71+
// yields the same values for all the fields.
72+
- (void)testAPNSInfoEncodingAndDecoding {
73+
NSDictionary *validDictionary = @{
74+
kFIRMessagingTokenOptionsAPNSKey : [@"tokenData" dataUsingEncoding:NSUTF8StringEncoding],
75+
kFIRMessagingTokenOptionsAPNSIsSandboxKey : @"sandboxValueAsString"
76+
};
77+
FIRMessagingAPNSInfo *info =
78+
[[FIRMessagingAPNSInfo alloc] initWithTokenOptionsDictionary:validDictionary];
79+
#pragma clang diagnostic push
80+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
81+
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:info];
82+
FIRMessagingAPNSInfo *restoredInfo = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
83+
#pragma clang diagnostic pop
84+
XCTAssertEqualObjects(info.deviceToken, restoredInfo.deviceToken);
85+
XCTAssertEqual(info.sandbox, restoredInfo.sandbox);
86+
}
87+
88+
@end

0 commit comments

Comments
 (0)