-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathTLSContextTests.swift
More file actions
69 lines (53 loc) · 2.61 KB
/
TLSContextTests.swift
File metadata and controls
69 lines (53 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.
import XCTest
@testable import AwsCommonRuntimeKit
class TLSContextTests: XCBaseTestCase {
func testCreateTlsContextWithOptions() throws {
let options = TLSContextOptions()
let context = try TLSContext(options: options, mode: .client)
_ = TLSConnectionOptions(context: context)
}
#if os(macOS) || os(Linux) || os(Android)
func testCreateTlsContextWithFilePath() throws {
let certPath = try getEnvironmentVarOrSkipTest(
environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_CERT")
let privateKeyPath = try getEnvironmentVarOrSkipTest(
environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_KEY")
let options = try TLSContextOptions.makeMTLS(
certificatePath: certPath, privateKeyPath: privateKeyPath)
let context = try TLSContext(options: options, mode: .client)
_ = TLSConnectionOptions(context: context)
}
#endif
#if os(macOS) || os(Linux) || os(Android)
func testCreateTlsContextWithData() throws {
let certPath = try getEnvironmentVarOrSkipTest(
environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_CERT")
let privateKeyPath = try getEnvironmentVarOrSkipTest(
environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_KEY")
let certificateData = try Data(contentsOf: URL(fileURLWithPath: certPath))
let privateKeyData = try Data(contentsOf: URL(fileURLWithPath: privateKeyPath))
let options = try TLSContextOptions.makeMTLS(
certificateData: certificateData, privateKeyData: privateKeyData)
let context = try TLSContext(options: options, mode: .client)
_ = TLSConnectionOptions(context: context)
}
#endif
#if AWS_USE_SECITEM
func testCreateTlsContextWithSecitemOptions() throws {
try skipIfPlatformDoesntSupportTLS()
let certPath = try getEnvironmentVarOrSkipTest(
environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_CERT")
let privateKeyPath = try getEnvironmentVarOrSkipTest(
environmentVarName: "AWS_TEST_MQTT311_IOT_CORE_X509_KEY")
let certificateData = try Data(contentsOf: URL(fileURLWithPath: certPath))
let privateKeyData = try Data(contentsOf: URL(fileURLWithPath: privateKeyPath))
let options = try TLSContextOptions.makeMTLS(
certificateData: certificateData, privateKeyData: privateKeyData)
try options.setSecitemLabels(certLabel: "TEST_CERT_LABEL", keyLabel: "TEST_KEY_LABEL")
let context = try TLSContext(options: options, mode: .client)
_ = TLSConnectionOptions(context: context)
}
#endif
}