More unit tests & disable XCBeautify for CI testing

pull/941/head
Morgan Pretty 2 years ago
parent 08337fe0fa
commit f5f112a593

@ -92,7 +92,7 @@ local update_cocoapods_cache = {
name: 'Run Unit Tests',
commands: [
'mkdir build',
'NSUnbufferedIO=YES set -o pipefail && xcodebuild test -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -parallelizeTargets -destination "platform=iOS Simulator,name=iPhone 14" -parallel-testing-enabled YES -parallel-testing-worker-count 2 -test-timeouts-enabled YES -maximum-test-execution-time-allowance 10 -collect-test-diagnostics never 2>&1 | ./Pods/xcbeautify/xcbeautify --is-ci'
'NSUnbufferedIO=YES set -o pipefail && xcodebuild test -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -parallelizeTargets -destination "platform=iOS Simulator,name=iPhone 14" -parallel-testing-enabled YES -parallel-testing-worker-count 2 -test-timeouts-enabled YES -maximum-test-execution-time-allowance 10 -collect-test-diagnostics never 2>&1'
],
},
{

@ -561,7 +561,11 @@ class ThreadDisappearingMessagesSettingsViewModel: SessionTableViewModel, Naviga
threadId: threadId,
authorId: getUserSessionId(db, using: dependencies).hexString,
variant: .infoDisappearingMessagesUpdate,
body: updatedConfig.messageInfoString(with: nil, isPreviousOff: !originalConfig.isEnabled),
body: updatedConfig.messageInfoString(
with: nil,
isPreviousOff: !originalConfig.isEnabled,
using: dependencies
),
timestampMs: currentOffsetTimestampMs,
expiresInSeconds: (updatedConfig.isEnabled ? nil : originalConfig.durationSeconds),
expiresStartedAtMs: (!updatedConfig.isEnabled && originalConfig.type == .disappearAfterSend ? Double(currentOffsetTimestampMs) : nil)

@ -229,7 +229,7 @@ public extension DisappearingMessagesConfiguration {
floor(durationSeconds).formatted(format: .long)
}
func messageInfoString(with senderName: String?, isPreviousOff: Bool) -> String? {
func messageInfoString(with senderName: String?, isPreviousOff: Bool, using dependencies: Dependencies) -> String? {
let messageInfo: MessageInfo = DisappearingMessagesConfiguration.MessageInfo(
senderName: senderName,
isEnabled: isEnabled,
@ -238,7 +238,9 @@ public extension DisappearingMessagesConfiguration {
isPreviousOff: isPreviousOff
)
guard let messageInfoData: Data = try? JSONEncoder().encode(messageInfo) else { return nil }
guard let messageInfoData: Data = try? JSONEncoder(using: dependencies).encode(messageInfo) else {
return nil
}
return String(data: messageInfoData, encoding: .utf8)
}

@ -1,4 +1,6 @@
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
//
// stringlint:disable
import Foundation
import GRDB

@ -126,7 +126,8 @@ extension MessageReceiver {
Profile.displayName(db, id: sender) :
nil
),
isPreviousOff: false
isPreviousOff: false,
using: dependencies
),
timestampMs: timestampMs,
wasRead: SessionUtil.timestampAlreadyRead(
@ -204,7 +205,8 @@ extension MessageReceiver {
Profile.displayName(db, id: sender) :
nil
),
isPreviousOff: !localConfig.isEnabled
isPreviousOff: !localConfig.isEnabled,
using: dependencies
),
timestampMs: protoLastChangeTimestampMs,
expiresInSeconds: (remoteConfig.isEnabled ? remoteConfig.durationSeconds : localConfig.durationSeconds),

@ -340,7 +340,16 @@ extension MessageReceiver {
) throws {
guard
let sender: String = message.sender,
let sentTimestampMs: UInt64 = message.sentTimestamp
let sentTimestampMs: UInt64 = message.sentTimestamp,
Authentication.verify(
signature: message.adminSignature,
publicKey: groupSessionId.publicKey,
verificationBytes: GroupUpdateInfoChangeMessage.generateVerificationBytes(
changeType: message.changeType,
timestampMs: sentTimestampMs
),
using: dependencies
)
else { throw MessageReceiverError.invalidMessage }
// Add a record of the specific change to the conversation (the actual change is handled via
@ -397,7 +406,8 @@ extension MessageReceiver {
Profile.displayName(db, id: sender) :
nil
),
isPreviousOff: false
isPreviousOff: false,
using: dependencies
),
timestampMs: Int64(sentTimestampMs),
wasRead: SessionUtil.timestampAlreadyRead(
@ -421,7 +431,16 @@ extension MessageReceiver {
) throws {
guard
let sender: String = message.sender,
let sentTimestampMs: UInt64 = message.sentTimestamp
let sentTimestampMs: UInt64 = message.sentTimestamp,
Authentication.verify(
signature: message.adminSignature,
publicKey: groupSessionId.publicKey,
verificationBytes: GroupUpdateMemberChangeMessage.generateVerificationBytes(
changeType: message.changeType,
timestampMs: sentTimestampMs
),
using: dependencies
)
else { throw MessageReceiverError.invalidMessage }
let profiles: [String: Profile] = (try? Profile

@ -216,6 +216,18 @@ class MessageReceiverGroupsSpec: QuickSpec {
return result
}()
@TestState var infoChangedMessage: GroupUpdateInfoChangeMessage! = {
let result: GroupUpdateInfoChangeMessage = GroupUpdateInfoChangeMessage(
changeType: .name,
updatedName: "TestGroup Rename",
updatedExpiration: nil,
adminSignature: .standard(signature: "TestSignature".bytes)
)
result.sender = "051111111111111111111111111111111111111111111111111111111111111111"
result.sentTimestamp = 1234567800
return result
}()
@TestState var deleteMessage: Data! = try! LibSessionMessage.groupKicked(
memberId: "05\(TestConstants.publicKey)",
groupKeysGen: 1
@ -992,6 +1004,178 @@ class MessageReceiverGroupsSpec: QuickSpec {
}
}
// MARK: -- when receiving an info changed message
context("when receiving an info changed message") {
beforeEach {
mockStorage.write(using: dependencies) { db in
try SessionThread.fetchOrCreate(
db,
id: groupId.hexString,
variant: .group,
shouldBeVisible: true,
calledFromConfigHandling: false,
using: dependencies
)
}
}
// MARK: -- fails if there is no sender
it("fails if there is no sender") {
infoChangedMessage.sender = nil
mockStorage.write { db in
expect {
try MessageReceiver.handleGroupUpdateMessage(
db,
threadId: groupId.hexString,
threadVariant: .group,
message: infoChangedMessage,
using: dependencies
)
}.to(throwError(MessageReceiverError.invalidMessage))
}
}
// MARK: -- fails if there is no timestamp
it("fails if there is no timestamp") {
infoChangedMessage.sentTimestamp = nil
mockStorage.write { db in
expect {
try MessageReceiver.handleGroupUpdateMessage(
db,
threadId: groupId.hexString,
threadVariant: .group,
message: infoChangedMessage,
using: dependencies
)
}.to(throwError(MessageReceiverError.invalidMessage))
}
}
// MARK: -- fails the the admin signature fails to verify
it("fails the the admin signature fails to verify") {
mockCrypto
.when { $0.verify(.signature(message: .any, publicKey: .any, signature: .any)) }
.thenReturn(false)
mockStorage.write { db in
expect {
try MessageReceiver.handleGroupUpdateMessage(
db,
threadId: groupId.hexString,
threadVariant: .group,
message: infoChangedMessage,
using: dependencies
)
}.to(throwError(MessageReceiverError.invalidMessage))
}
}
// MARK: -- for a name change
context("for a name change") {
// MARK: -- creates the correct control message
it("creates the correct control message") {
mockStorage.write { db in
try MessageReceiver.handleGroupUpdateMessage(
db,
threadId: groupId.hexString,
threadVariant: .group,
message: infoChangedMessage,
using: dependencies
)
}
let interaction: Interaction? = mockStorage.read { db in try Interaction.fetchOne(db) }
expect(interaction?.timestampMs).to(equal(1234567800))
expect(interaction?.body).to(equal(
ClosedGroup.MessageInfo
.updatedName("TestGroup Rename")
.infoString(using: dependencies)
))
}
}
// MARK: -- for a display picture change
context("for a display picture change") {
beforeEach {
infoChangedMessage = GroupUpdateInfoChangeMessage(
changeType: .avatar,
updatedName: nil,
updatedExpiration: nil,
adminSignature: .standard(signature: "TestSignature".bytes)
)
infoChangedMessage.sender = "051111111111111111111111111111111111111111111111111111111111111111"
infoChangedMessage.sentTimestamp = 1234567800
}
// MARK: -- creates the correct control message
it("creates the correct control message") {
mockStorage.write { db in
try MessageReceiver.handleGroupUpdateMessage(
db,
threadId: groupId.hexString,
threadVariant: .group,
message: infoChangedMessage,
using: dependencies
)
}
let interaction: Interaction? = mockStorage.read { db in try Interaction.fetchOne(db) }
expect(interaction?.timestampMs).to(equal(1234567800))
expect(interaction?.body).to(equal(
ClosedGroup.MessageInfo
.updatedDisplayPicture
.infoString(using: dependencies)
))
}
}
// MARK: -- for a disappearing message setting change
context("for a disappearing message setting change") {
beforeEach {
infoChangedMessage = GroupUpdateInfoChangeMessage(
changeType: .disappearingMessages,
updatedName: nil,
updatedExpiration: 3600,
adminSignature: .standard(signature: "TestSignature".bytes)
)
infoChangedMessage.sender = "051111111111111111111111111111111111111111111111111111111111111111"
infoChangedMessage.sentTimestamp = 1234567800
}
// MARK: -- creates the correct control message
it("creates the correct control message") {
mockStorage.write { db in
try MessageReceiver.handleGroupUpdateMessage(
db,
threadId: groupId.hexString,
threadVariant: .group,
message: infoChangedMessage,
using: dependencies
)
}
let interaction: Interaction? = mockStorage.read { db in try Interaction.fetchOne(db) }
expect(interaction?.timestampMs).to(equal(1234567800))
expect(interaction?.body).to(equal(
DisappearingMessagesConfiguration(
threadId: groupId.hexString,
isEnabled: true,
durationSeconds: 3600,
type: .disappearAfterSend,
lastChangeTimestampMs: nil
).messageInfoString(
with: infoChangedMessage.sender,
isPreviousOff: false,
using: dependencies
)
))
expect(interaction?.expiresInSeconds).to(equal(0))
}
}
}
// MARK: -- when receiving a delete message
context("when receiving a delete message") {
beforeEach {

Loading…
Cancel
Save