mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
CR: test malformed protos
This commit is contained in:
parent
e5856b2ac5
commit
d39906f606
|
@ -431,6 +431,7 @@
|
||||||
4C13C9F620E57BA30089A98B /* ColorPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C13C9F520E57BA30089A98B /* ColorPickerViewController.swift */; };
|
4C13C9F620E57BA30089A98B /* ColorPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C13C9F520E57BA30089A98B /* ColorPickerViewController.swift */; };
|
||||||
4C20B2B720CA0034001BAC90 /* ThreadViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4542DF51208B82E9007B4E76 /* ThreadViewModel.swift */; };
|
4C20B2B720CA0034001BAC90 /* ThreadViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4542DF51208B82E9007B4E76 /* ThreadViewModel.swift */; };
|
||||||
4C20B2B920CA10DE001BAC90 /* ConversationSearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */; };
|
4C20B2B920CA10DE001BAC90 /* ConversationSearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */; };
|
||||||
|
4C3EF802210918740007EBF7 /* SSKEnvelopeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C3EF801210918740007EBF7 /* SSKEnvelopeTest.swift */; };
|
||||||
4C4AEC4520EC343B0020E72B /* DismissableTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */; };
|
4C4AEC4520EC343B0020E72B /* DismissableTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */; };
|
||||||
4C4BC6C32102D697004040C9 /* ContactDiscoveryOperationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */; };
|
4C4BC6C32102D697004040C9 /* ContactDiscoveryOperationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */; };
|
||||||
4C6F527C20FFE8400097DEEE /* SignalUBSan.supp in Resources */ = {isa = PBXBuildFile; fileRef = 4C6F527B20FFE8400097DEEE /* SignalUBSan.supp */; };
|
4C6F527C20FFE8400097DEEE /* SignalUBSan.supp in Resources */ = {isa = PBXBuildFile; fileRef = 4C6F527B20FFE8400097DEEE /* SignalUBSan.supp */; };
|
||||||
|
@ -1110,6 +1111,7 @@
|
||||||
4C11AA4F20FD59C700351FBD /* MessageStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageStatusView.swift; sourceTree = "<group>"; };
|
4C11AA4F20FD59C700351FBD /* MessageStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageStatusView.swift; sourceTree = "<group>"; };
|
||||||
4C13C9F520E57BA30089A98B /* ColorPickerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerViewController.swift; sourceTree = "<group>"; };
|
4C13C9F520E57BA30089A98B /* ColorPickerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerViewController.swift; sourceTree = "<group>"; };
|
||||||
4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationSearchViewController.swift; sourceTree = "<group>"; };
|
4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationSearchViewController.swift; sourceTree = "<group>"; };
|
||||||
|
4C3EF801210918740007EBF7 /* SSKEnvelopeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSKEnvelopeTest.swift; sourceTree = "<group>"; };
|
||||||
4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissableTextField.swift; sourceTree = "<group>"; };
|
4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissableTextField.swift; sourceTree = "<group>"; };
|
||||||
4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ContactDiscoveryOperationTest.swift; path = contact/ContactDiscoveryOperationTest.swift; sourceTree = "<group>"; };
|
4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ContactDiscoveryOperationTest.swift; path = contact/ContactDiscoveryOperationTest.swift; sourceTree = "<group>"; };
|
||||||
4C6F527B20FFE8400097DEEE /* SignalUBSan.supp */ = {isa = PBXFileReference; lastKnownFileType = text; path = SignalUBSan.supp; sourceTree = "<group>"; };
|
4C6F527B20FFE8400097DEEE /* SignalUBSan.supp */ = {isa = PBXFileReference; lastKnownFileType = text; path = SignalUBSan.supp; sourceTree = "<group>"; };
|
||||||
|
@ -2109,6 +2111,14 @@
|
||||||
path = Speakerbox;
|
path = Speakerbox;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
4C3EF8002109184A0007EBF7 /* SSKTests */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
4C3EF801210918740007EBF7 /* SSKEnvelopeTest.swift */,
|
||||||
|
);
|
||||||
|
path = SSKTests;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
76EB03C118170B33006006FC /* src */ = {
|
76EB03C118170B33006006FC /* src */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
@ -2284,6 +2294,7 @@
|
||||||
B660F66C1C29867F00687D6E /* test */ = {
|
B660F66C1C29867F00687D6E /* test */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
4C3EF8002109184A0007EBF7 /* SSKTests */,
|
||||||
34C6B0A41FA0E46F00D35993 /* Assets */,
|
34C6B0A41FA0E46F00D35993 /* Assets */,
|
||||||
B660F6731C29867F00687D6E /* call */,
|
B660F6731C29867F00687D6E /* call */,
|
||||||
B660F6751C29867F00687D6E /* contact */,
|
B660F6751C29867F00687D6E /* contact */,
|
||||||
|
@ -3454,6 +3465,7 @@
|
||||||
B660F6DA1C29868000687D6E /* ExceptionsTest.m in Sources */,
|
B660F6DA1C29868000687D6E /* ExceptionsTest.m in Sources */,
|
||||||
B660F6DB1C29868000687D6E /* FunctionalUtilTest.m in Sources */,
|
B660F6DB1C29868000687D6E /* FunctionalUtilTest.m in Sources */,
|
||||||
45E7A6A81E71CA7E00D44FB5 /* DisplayableTextFilterTest.swift in Sources */,
|
45E7A6A81E71CA7E00D44FB5 /* DisplayableTextFilterTest.swift in Sources */,
|
||||||
|
4C3EF802210918740007EBF7 /* SSKEnvelopeTest.swift in Sources */,
|
||||||
452D1AF12081059C00A67F7F /* StringAdditionsTest.swift in Sources */,
|
452D1AF12081059C00A67F7F /* StringAdditionsTest.swift in Sources */,
|
||||||
4C4BC6C32102D697004040C9 /* ContactDiscoveryOperationTest.swift in Sources */,
|
4C4BC6C32102D697004040C9 /* ContactDiscoveryOperationTest.swift in Sources */,
|
||||||
B660F6BB1C29868000687D6E /* OWSContactsManagerTest.m in Sources */,
|
B660F6BB1C29868000687D6E /* OWSContactsManagerTest.m in Sources */,
|
||||||
|
|
68
Signal/test/SSKTests/SSKEnvelopeTest.swift
Normal file
68
Signal/test/SSKTests/SSKEnvelopeTest.swift
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
import SignalServiceKit
|
||||||
|
import SwiftProtobuf
|
||||||
|
|
||||||
|
class SSKEnvelopeTest: XCTestCase {
|
||||||
|
|
||||||
|
override func setUp() {
|
||||||
|
super.setUp()
|
||||||
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tearDown() {
|
||||||
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||||
|
super.tearDown()
|
||||||
|
}
|
||||||
|
|
||||||
|
func testParse_EmptyData() {
|
||||||
|
let data = Data()
|
||||||
|
XCTAssertThrowsError(try SSKEnvelope(serializedData: data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testParse_UnparseableData() {
|
||||||
|
let data = "asdf".data(using: .utf8)!
|
||||||
|
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { error in
|
||||||
|
XCTAssert(error is SwiftProtobuf.BinaryDecodingError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testParse_ValidData() {
|
||||||
|
// `encodedData` was derived thus:
|
||||||
|
// let builder = OWSSignalServiceProtosEnvelopeBuilder()
|
||||||
|
// builder.setTimestamp(NSDate.ows_millisecondTimeStamp())
|
||||||
|
// builder.setSource("+15551231234")
|
||||||
|
// builder.setSourceDevice(1)
|
||||||
|
// builder.setType(OWSSignalServiceProtosEnvelopeType.ciphertext)
|
||||||
|
// let encodedData = builder.build().data()!.base64EncodedString()
|
||||||
|
let encodedData = "CAESDCsxNTU1MTIzMTIzNCjKm4WazSw4AQ=="
|
||||||
|
let data = Data(base64Encoded: encodedData)!
|
||||||
|
|
||||||
|
XCTAssertNoThrow(try SSKEnvelope(serializedData: data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testParse_invalidData() {
|
||||||
|
// `encodedData` was derived thus:
|
||||||
|
// let builder = OWSSignalServiceProtosEnvelopeBuilder()
|
||||||
|
// builder.setTimestamp(NSDate.ows_millisecondTimeStamp())
|
||||||
|
// builder.setSource("+15551231234")
|
||||||
|
// builder.setSourceDevice(1)
|
||||||
|
// // MISSING TYPE!
|
||||||
|
// let encodedData = builder.build().data()!.base64EncodedString()
|
||||||
|
let encodedData = "EgwrMTU1NTEyMzEyMzQojdmOms0sOAE="
|
||||||
|
let data = Data(base64Encoded: encodedData)!
|
||||||
|
|
||||||
|
XCTAssertThrowsError(try SSKEnvelope(serializedData: data)) { (error) -> Void in
|
||||||
|
switch error {
|
||||||
|
case SSKEnvelope.EnvelopeError.invalidProtobuf:
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
XCTFail("unexpected error: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import Foundation
|
||||||
@objc
|
@objc
|
||||||
public class SSKEnvelope: NSObject {
|
public class SSKEnvelope: NSObject {
|
||||||
|
|
||||||
enum EnvelopeError: Error {
|
public enum EnvelopeError: Error {
|
||||||
case invalidProtobuf(description: String)
|
case invalidProtobuf(description: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue