Skip to content

Commit 94ab466

Browse files
authored
Make the URLs used by Google Data Transport available in a Public API. (#7167)
1 parent 342314d commit 94ab466

File tree

14 files changed

+220
-94
lines changed

14 files changed

+220
-94
lines changed

FirebasePerformance.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Firebase Performance library to measure performance of Mobile and Web Apps.
2828
base_dir + 'ProtoSupport/**/*.[mh]',
2929
'FirebaseCore/Sources/Private/*.h',
3030
'FirebaseRemoteConfig/Sources/Private/*.h',
31+
'GoogleDataTransport/GDTCORLibrary/Internal/*.h',
3132
'GoogleUtilities/ISASwizzler/Private/*.h',
3233
'GoogleUtilities/MethodSwizzler/Private/*.h',
3334
'GoogleUtilities/Environment/Private/*.h',
@@ -58,7 +59,7 @@ Firebase Performance library to measure performance of Mobile and Web Apps.
5859
s.dependency 'FirebaseCore', '~> 7.0'
5960
s.dependency 'FirebaseInstallations', '~> 7.0'
6061
s.dependency 'FirebaseRemoteConfig', '~> 7.0'
61-
s.dependency 'GoogleDataTransport', '~> 8.1'
62+
s.dependency 'GoogleDataTransport', '~> 8.2'
6263
s.dependency 'GTMSessionFetcher/Core', '~> 1.1'
6364
s.dependency 'GoogleToolboxForMac/Logger', '~> 2.1'
6465
s.dependency 'GoogleUtilities/Environment', '~> 7.0'

FirebasePerformance/Sources/FPRURLFilter.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#import "FirebasePerformance/Sources/FPRConsoleLogger.h"
1919

20-
#import "GoogleDataTransport/GDTCCTLibrary/Private/GDTCCTUploader.h"
20+
#import "GoogleDataTransport/GDTCORLibrary/Internal/GoogleDataTransportInternal.h"
2121

2222
/** The expected key of the domain allowlist array. */
2323
static NSString *const kFPRAllowlistDomainsKey = @"FPRWhitelistedDomains";
@@ -44,9 +44,9 @@ typedef NS_ENUM(NSInteger, FPRURLAllowlistStatus) {
4444
static NSSet *denylist = nil;
4545
static dispatch_once_t onceToken;
4646
dispatch_once(&onceToken, ^{
47-
NSDictionary<NSNumber *, NSURL *> *URLs = [GDTCCTUploader uploadURLs];
4847
denylist = [[NSSet alloc] initWithArray:@[
49-
URLs[@(kGDTCORTargetCCT)].absoluteString, URLs[@(kGDTCORTargetFLL)].absoluteString
48+
[[GDTCOREndpoints uploadURLForTarget:kGDTCORTargetCCT] absoluteString],
49+
[[GDTCOREndpoints uploadURLForTarget:kGDTCORTargetFLL] absoluteString]
5050
]];
5151
});
5252
return denylist;

FirebasePerformance/Tests/Unit/FPRURLFilterTests.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#import "FirebasePerformance/Tests/Unit/Fakes/NSBundleFake.h"
2121

22-
#import "GoogleDataTransport/GDTCCTLibrary/Private/GDTCCTUploader.h"
22+
#import "GoogleDataTransport/GDTCORLibrary/Internal/GoogleDataTransportInternal.h"
2323

2424
@interface FPRURLFilterTest : XCTestCase
2525

@@ -39,16 +39,14 @@ - (void)testClearcutURLAllowed {
3939

4040
/** Tests that the Clearcut upload URL is denied. */
4141
- (void)testFllClearcutURLDenied {
42-
NSDictionary<NSNumber *, NSURL *> *uploadURLs = [GDTCCTUploader uploadURLs];
4342
XCTAssertFalse([[FPRURLFilter sharedInstance]
44-
shouldInstrumentURL:uploadURLs[@(kGDTCORTargetCCT)].absoluteString]);
43+
shouldInstrumentURL:[GDTCOREndpoints uploadURLForTarget:kGDTCORTargetCCT].absoluteString]);
4544
}
4645

4746
/** Tests that the FLL upload URL is denied. */
4847
- (void)testFllServiceURLDenied {
49-
NSDictionary<NSNumber *, NSURL *> *uploadURLs = [GDTCCTUploader uploadURLs];
5048
XCTAssertFalse([[FPRURLFilter sharedInstance]
51-
shouldInstrumentURL:uploadURLs[@(kGDTCORTargetFLL)].absoluteString]);
49+
shouldInstrumentURL:[GDTCOREndpoints uploadURLForTarget:kGDTCORTargetFLL].absoluteString]);
5250
}
5351

5452
/** Tests shouldInstrument when the plist file is not being used. */

GoogleDataTransport.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'GoogleDataTransport'
3-
s.version = '8.1.0'
3+
s.version = '8.2.0'
44
s.summary = 'Google iOS SDK data transport.'
55

66
s.description = <<-DESC

GoogleDataTransport/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v8.2.0
2+
- Expose upload URLs as a public API for Firebase Performance to use for denying instrumentation those URLs.
3+
14
# v8.1.0
25
- Expose upload URLs which FirebasePerformance will depend upon.
36
- Fix out-of-memory crash for a big amount of pending events. (#6995)

GoogleDataTransport/GDTCCTLibrary/GDTCCTUploader.m

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORRegistrar.h"
2121
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORStorageProtocol.h"
2222
#import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCORConsoleLogger.h"
23+
#import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCOREndpoints.h"
2324
#import "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCOREvent.h"
2425

2526
#import <nanopb/pb.h>
@@ -50,9 +51,6 @@
5051
/** */
5152
static NSString *const kLibraryDataFLLNextUploadTimeKey = @"GDTCCTUploaderFLLNextUploadTimeKey";
5253

53-
static NSString *const kINTServerURL =
54-
@"https://dummyapiverylong-dummy.dummy.com/dummy/api/very/long";
55-
5654
#if !NDEBUG
5755
NSNotificationName const GDTCCTUploadCompleteNotification = @"com.GDTCCTUploader.UploadComplete";
5856
#endif // #if !NDEBUG
@@ -108,78 +106,14 @@ + (NSURL *_Nullable)testServerURL {
108106
return _testServerURL;
109107
}
110108

111-
+ (NSDictionary<NSNumber *, NSURL *> *)uploadURLs {
112-
// These strings should be interleaved to construct the real URL. This is just to (hopefully)
113-
// fool github URL scanning bots.
114-
static NSURL *CCTServerURL;
115-
static dispatch_once_t CCTOnceToken;
116-
dispatch_once(&CCTOnceToken, ^{
117-
const char *p1 = "hts/frbslgiggolai.o/0clgbth";
118-
const char *p2 = "tp:/ieaeogn.ogepscmvc/o/ac";
119-
const char URL[54] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3], p2[3], p1[4],
120-
p2[4], p1[5], p2[5], p1[6], p2[6], p1[7], p2[7], p1[8], p2[8],
121-
p1[9], p2[9], p1[10], p2[10], p1[11], p2[11], p1[12], p2[12], p1[13],
122-
p2[13], p1[14], p2[14], p1[15], p2[15], p1[16], p2[16], p1[17], p2[17],
123-
p1[18], p2[18], p1[19], p2[19], p1[20], p2[20], p1[21], p2[21], p1[22],
124-
p2[22], p1[23], p2[23], p1[24], p2[24], p1[25], p2[25], p1[26], '\0'};
125-
CCTServerURL = [NSURL URLWithString:[NSString stringWithUTF8String:URL]];
126-
});
127-
128-
static NSURL *FLLServerURL;
129-
static dispatch_once_t FLLOnceToken;
130-
dispatch_once(&FLLOnceToken, ^{
131-
const char *p1 = "hts/frbslgigp.ogepscmv/ieo/eaybtho";
132-
const char *p2 = "tp:/ieaeogn-agolai.o/1frlglgc/aclg";
133-
const char URL[69] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3], p2[3], p1[4],
134-
p2[4], p1[5], p2[5], p1[6], p2[6], p1[7], p2[7], p1[8], p2[8],
135-
p1[9], p2[9], p1[10], p2[10], p1[11], p2[11], p1[12], p2[12], p1[13],
136-
p2[13], p1[14], p2[14], p1[15], p2[15], p1[16], p2[16], p1[17], p2[17],
137-
p1[18], p2[18], p1[19], p2[19], p1[20], p2[20], p1[21], p2[21], p1[22],
138-
p2[22], p1[23], p2[23], p1[24], p2[24], p1[25], p2[25], p1[26], p2[26],
139-
p1[27], p2[27], p1[28], p2[28], p1[29], p2[29], p1[30], p2[30], p1[31],
140-
p2[31], p1[32], p2[32], p1[33], p2[33], '\0'};
141-
FLLServerURL = [NSURL URLWithString:[NSString stringWithUTF8String:URL]];
142-
});
143-
144-
static NSURL *CSHServerURL;
145-
static dispatch_once_t CSHOnceToken;
146-
dispatch_once(&CSHOnceToken, ^{
147-
// These strings should be interleaved to construct the real URL. This is just to (hopefully)
148-
// fool github URL scanning bots.
149-
const char *p1 = "hts/cahyiseot-agolai.o/1frlglgc/aclg";
150-
const char *p2 = "tp:/rsltcrprsp.ogepscmv/ieo/eaybtho";
151-
const char URL[72] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3], p2[3], p1[4],
152-
p2[4], p1[5], p2[5], p1[6], p2[6], p1[7], p2[7], p1[8], p2[8],
153-
p1[9], p2[9], p1[10], p2[10], p1[11], p2[11], p1[12], p2[12], p1[13],
154-
p2[13], p1[14], p2[14], p1[15], p2[15], p1[16], p2[16], p1[17], p2[17],
155-
p1[18], p2[18], p1[19], p2[19], p1[20], p2[20], p1[21], p2[21], p1[22],
156-
p2[22], p1[23], p2[23], p1[24], p2[24], p1[25], p2[25], p1[26], p2[26],
157-
p1[27], p2[27], p1[28], p2[28], p1[29], p2[29], p1[30], p2[30], p1[31],
158-
p2[31], p1[32], p2[32], p1[33], p2[33], p1[34], p2[34], p1[35], '\0'};
159-
CSHServerURL = [NSURL URLWithString:[NSString stringWithUTF8String:URL]];
160-
});
161-
static NSDictionary<NSNumber *, NSURL *> *uploadURLs;
162-
static dispatch_once_t URLOnceToken;
163-
dispatch_once(&URLOnceToken, ^{
164-
uploadURLs = @{
165-
@(kGDTCORTargetCCT) : CCTServerURL,
166-
@(kGDTCORTargetFLL) : FLLServerURL,
167-
@(kGDTCORTargetCSH) : CSHServerURL,
168-
@(kGDTCORTargetINT) : [NSURL URLWithString:kINTServerURL]
169-
};
170-
});
171-
return uploadURLs;
172-
}
173-
174109
+ (nullable NSURL *)serverURLForTarget:(GDTCORTarget)target {
175110
#if !NDEBUG
176111
if (_testServerURL) {
177112
return _testServerURL;
178113
}
179114
#endif // !NDEBUG
180115

181-
NSDictionary<NSNumber *, NSURL *> *uploadURLs = [self uploadURLs];
182-
return uploadURLs[@(target)];
116+
return [GDTCOREndpoints uploadURLForTarget:target];
183117
}
184118

185119
- (instancetype)init {

GoogleDataTransport/GDTCCTLibrary/Private/GDTCCTUploader.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ extern NSNotificationName const GDTCCTUploadCompleteNotification;
2828
/** Class capable of uploading events to the CCT backend. */
2929
@interface GDTCCTUploader : NSObject <GDTCORUploader>
3030

31-
/** Returns the server URL for target.*/
32-
// TODO: create a separate public header (e.g. GDTCCTUploadURL.h) to make it a public API.
33-
+ (NSDictionary<NSNumber *, NSURL *> *)uploadURLs;
34-
3531
/** The queue on which all CCT uploading will occur. */
3632
@property(nonatomic, readonly) dispatch_queue_t uploaderQueue;
3733

GoogleDataTransport/GDTCCTTests/Unit/GDTCCTUploaderTest.m

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ - (void)tearDown {
7373

7474
#pragma mark - Upload flow tests
7575

76-
- (void)testUploadURLsAreCorrect {
77-
GDTCCTUploader.testServerURL = nil;
78-
NSDictionary<NSNumber *, NSURL *> *URLs = GDTCCTUploader.uploadURLs;
79-
XCTAssertEqualObjects(URLs[@(kGDTCORTargetCCT)], [self serverURLForTarget:kGDTCORTargetCCT]);
80-
XCTAssertEqualObjects(URLs[@(kGDTCORTargetFLL)], [self serverURLForTarget:kGDTCORTargetFLL]);
81-
XCTAssertEqualObjects(URLs[@(kGDTCORTargetCSH)], [self serverURLForTarget:kGDTCORTargetCSH]);
82-
XCTAssertEqualObjects(URLs[@(kGDTCORTargetINT)], [self serverURLForTarget:kGDTCORTargetINT]);
83-
GDTCCTUploader.testServerURL =
84-
[self.testServer.serverURL URLByAppendingPathComponent:@"logBatch"];
85-
}
86-
8776
- (void)testUploadTargetWhenThereAreEventsToUpload {
8877
// 0. Generate test events.
8978
id<GDTCORStorageProtocol> storage = GDTCORStorageInstanceForTarget(kGDTCORTargetTest);
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2020 Google LLC
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 "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCOREndpoints.h"
18+
19+
static NSString *const kINTServerURL =
20+
@"https://dummyapiverylong-dummy.dummy.com/dummy/api/very/long";
21+
22+
@implementation GDTCOREndpoints
23+
24+
+ (NSDictionary<NSNumber *, NSURL *> *)uploadURLs {
25+
// These strings should be interleaved to construct the real URL. This is just to (hopefully)
26+
// fool github URL scanning bots.
27+
static NSURL *CCTServerURL;
28+
static dispatch_once_t CCTOnceToken;
29+
dispatch_once(&CCTOnceToken, ^{
30+
const char *p1 = "hts/frbslgiggolai.o/0clgbth";
31+
const char *p2 = "tp:/ieaeogn.ogepscmvc/o/ac";
32+
const char URL[54] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3], p2[3], p1[4],
33+
p2[4], p1[5], p2[5], p1[6], p2[6], p1[7], p2[7], p1[8], p2[8],
34+
p1[9], p2[9], p1[10], p2[10], p1[11], p2[11], p1[12], p2[12], p1[13],
35+
p2[13], p1[14], p2[14], p1[15], p2[15], p1[16], p2[16], p1[17], p2[17],
36+
p1[18], p2[18], p1[19], p2[19], p1[20], p2[20], p1[21], p2[21], p1[22],
37+
p2[22], p1[23], p2[23], p1[24], p2[24], p1[25], p2[25], p1[26], '\0'};
38+
CCTServerURL = [NSURL URLWithString:[NSString stringWithUTF8String:URL]];
39+
});
40+
41+
static NSURL *FLLServerURL;
42+
static dispatch_once_t FLLOnceToken;
43+
dispatch_once(&FLLOnceToken, ^{
44+
const char *p1 = "hts/frbslgigp.ogepscmv/ieo/eaybtho";
45+
const char *p2 = "tp:/ieaeogn-agolai.o/1frlglgc/aclg";
46+
const char URL[69] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3], p2[3], p1[4],
47+
p2[4], p1[5], p2[5], p1[6], p2[6], p1[7], p2[7], p1[8], p2[8],
48+
p1[9], p2[9], p1[10], p2[10], p1[11], p2[11], p1[12], p2[12], p1[13],
49+
p2[13], p1[14], p2[14], p1[15], p2[15], p1[16], p2[16], p1[17], p2[17],
50+
p1[18], p2[18], p1[19], p2[19], p1[20], p2[20], p1[21], p2[21], p1[22],
51+
p2[22], p1[23], p2[23], p1[24], p2[24], p1[25], p2[25], p1[26], p2[26],
52+
p1[27], p2[27], p1[28], p2[28], p1[29], p2[29], p1[30], p2[30], p1[31],
53+
p2[31], p1[32], p2[32], p1[33], p2[33], '\0'};
54+
FLLServerURL = [NSURL URLWithString:[NSString stringWithUTF8String:URL]];
55+
});
56+
57+
static NSURL *CSHServerURL;
58+
static dispatch_once_t CSHOnceToken;
59+
dispatch_once(&CSHOnceToken, ^{
60+
// These strings should be interleaved to construct the real URL. This is just to (hopefully)
61+
// fool github URL scanning bots.
62+
const char *p1 = "hts/cahyiseot-agolai.o/1frlglgc/aclg";
63+
const char *p2 = "tp:/rsltcrprsp.ogepscmv/ieo/eaybtho";
64+
const char URL[72] = {p1[0], p2[0], p1[1], p2[1], p1[2], p2[2], p1[3], p2[3], p1[4],
65+
p2[4], p1[5], p2[5], p1[6], p2[6], p1[7], p2[7], p1[8], p2[8],
66+
p1[9], p2[9], p1[10], p2[10], p1[11], p2[11], p1[12], p2[12], p1[13],
67+
p2[13], p1[14], p2[14], p1[15], p2[15], p1[16], p2[16], p1[17], p2[17],
68+
p1[18], p2[18], p1[19], p2[19], p1[20], p2[20], p1[21], p2[21], p1[22],
69+
p2[22], p1[23], p2[23], p1[24], p2[24], p1[25], p2[25], p1[26], p2[26],
70+
p1[27], p2[27], p1[28], p2[28], p1[29], p2[29], p1[30], p2[30], p1[31],
71+
p2[31], p1[32], p2[32], p1[33], p2[33], p1[34], p2[34], p1[35], '\0'};
72+
CSHServerURL = [NSURL URLWithString:[NSString stringWithUTF8String:URL]];
73+
});
74+
static NSDictionary<NSNumber *, NSURL *> *uploadURLs;
75+
static dispatch_once_t URLOnceToken;
76+
dispatch_once(&URLOnceToken, ^{
77+
uploadURLs = @{
78+
@(kGDTCORTargetCCT) : CCTServerURL,
79+
@(kGDTCORTargetFLL) : FLLServerURL,
80+
@(kGDTCORTargetCSH) : CSHServerURL,
81+
@(kGDTCORTargetINT) : [NSURL URLWithString:kINTServerURL]
82+
};
83+
});
84+
return uploadURLs;
85+
}
86+
87+
+ (nullable NSURL *)uploadURLForTarget:(GDTCORTarget)target {
88+
NSDictionary<NSNumber *, NSURL *> *URLs = [self uploadURLs];
89+
return [URLs objectForKey:@(target)];
90+
}
91+
92+
@end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2020 Google LLC
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 "GoogleDataTransport/GDTCORLibrary/Public/GoogleDataTransport/GDTCOREndpoints.h"
18+
19+
@interface GDTCOREndpoints ()
20+
21+
/** Returns the list of all the upload URLs used by the transport library.
22+
*
23+
* @return Map of the transport target and the URL used for uploading the events for that target.
24+
*/
25+
+ (NSDictionary<NSNumber *, NSURL *> *)uploadURLs;
26+
27+
@end

0 commit comments

Comments
 (0)