Skip to content

Commit 3da8ee8

Browse files
authored
CBL-7355 : Ensure to use different CN in MultipeerReplicatorTest (#3436)
To avoid service name collisions in DNS-SD, ensure each peer uses a unique certificate common name (CN) when creating its TLSIdentity in tests.
1 parent 2d324c5 commit 3da8ee8

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Objective-C/Tests/MultipeerReplicatorTest.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,18 @@ - (CBLTLSIdentity*) issuer {
129129

130130
- (CBLTLSIdentity*) createIdentity {
131131
Assert(_identityCount++ <= kTestMaxIdentity);
132-
133132
NSError* error;
134-
NSString* name = [self identityNameForNumber: _identityCount];
135-
NSDictionary* attrs = @{ kCBLCertAttrCommonName: name };
133+
NSString* label = [self identityNameForNumber: _identityCount];
134+
135+
uint64_t timestamp = (uint64_t)([[NSDate date] timeIntervalSince1970] * 1000);
136+
NSString* cn = [NSString stringWithFormat: @"%@-%llu", label, timestamp];
137+
NSDictionary* attrs = @{ kCBLCertAttrCommonName: cn };
138+
136139
CBLTLSIdentity* identity = [CBLTLSIdentity createIdentityForKeyUsages: kTestKeyUsages
137140
attributes: attrs
138141
expiration: nil
139142
issuer: [self issuer]
140-
label: name
143+
label: label
141144
error: &error];
142145

143146
AssertNotNil(identity);
@@ -1185,7 +1188,6 @@ - (void) runConflictResolverTestWithResolver: (nullable MultipeerConflictResolve
11851188
18. Check the doc1 in both peers and verify that the its body is {"greeting": "howdy"}.
11861189
*/
11871190
- (void) testDefaultConflictResolver {
1188-
CBLLogSinks.console = [[CBLConsoleLogSink alloc] initWithLevel: kCBLLogLevelVerbose];
11891191
[self runConflictResolverTestWithResolver: nil verifyBlock: ^BOOL (CBLDocument* resolvedDoc) {
11901192
return [[resolvedDoc stringForKey: @"greeting"] isEqualToString: @"howdy"];
11911193
}];

Swift/Tests/MultipeerReplicatorTest.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,18 @@ class MultipeerReplicatorTest: CBLTestCase {
121121
assert(identityCount <= kTestMaxIdentity)
122122
identityCount += 1
123123

124-
let name = identityNameForNumber(identityCount)
125-
let attrs = [certAttrCommonName: name]
124+
let label = identityNameForNumber(identityCount)
125+
126+
let timestamp = UInt64(Date().timeIntervalSince1970 * 1000)
127+
let cn = "\(label)-\(timestamp)"
128+
let attrs = [certAttrCommonName: cn]
129+
126130
return try TLSIdentity.createIdentity(
127131
for: kTestKeyUsages,
128132
attributes: attrs,
129133
expiration: nil,
130134
issuer: self.issuer,
131-
label: name)
135+
label: label)
132136
}
133137

134138
typealias CollectionConfigBlock = (inout MultipeerCollectionConfiguration) -> Void

0 commit comments

Comments
 (0)