Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device farm Setup #274

Open
wants to merge 120 commits into
base: mqtt_test_app
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
e4d81d9
test build app with local personal account
xiazhvera Jul 3, 2024
a5884f9
check working directory
xiazhvera Jul 3, 2024
048ff00
allowProvisioningUpdates
xiazhvera Jul 8, 2024
2101343
import identity
xiazhvera Jul 8, 2024
e36bc23
setup aws role
xiazhvera Jul 8, 2024
4982500
test with CI provider id
xiazhvera Jul 8, 2024
e998a78
test secret manager result
xiazhvera Jul 8, 2024
4e7c3d9
remove print
xiazhvera Jul 8, 2024
ed8c714
import provision file
xiazhvera Jul 8, 2024
97923c8
fix syntax
xiazhvera Jul 8, 2024
82d6ac7
update provisoning file
xiazhvera Jul 9, 2024
7feedb4
test appium device farm
xiazhvera Jul 9, 2024
24aff2e
update export option
xiazhvera Jul 9, 2024
ccade28
fix file path
xiazhvera Jul 9, 2024
b280d6a
update script path
xiazhvera Jul 10, 2024
910abd6
add test suite
xiazhvera Jul 10, 2024
3e02cf8
rename python test file
xiazhvera Jul 10, 2024
01bba19
rename python test file
xiazhvera Jul 10, 2024
2ba917f
renmae test script
xiazhvera Jul 10, 2024
e108c9a
rename tests
xiazhvera Jul 10, 2024
f68eb32
clean up path
xiazhvera Jul 10, 2024
5e8ab6f
fix python script
xiazhvera Jul 10, 2024
9936abb
update secrets lingt
xiazhvera Jul 10, 2024
eb3e590
fix run command
xiazhvera Jul 10, 2024
b8ef280
clean up arn string
xiazhvera Jul 10, 2024
8956c55
fix working path
xiazhvera Jul 10, 2024
3b3be08
test with new test spec with appium
xiazhvera Jul 10, 2024
29d7fc6
update test spec to use df default
xiazhvera Jul 10, 2024
e2c66f1
fix spec upload type
xiazhvera Jul 10, 2024
3acbe94
ios13 quick test
xiazhvera Jul 15, 2024
2a20b95
test ios13
xiazhvera Jul 15, 2024
42fe763
ios13 environment only allow boto31.33.12
xiazhvera Jul 15, 2024
8019207
use boto3 1.28.1 for python3.7
xiazhvera Jul 15, 2024
9effcd6
update dependency for python3.y
xiazhvera Jul 15, 2024
4cfb606
update dependency
xiazhvera Jul 15, 2024
6953305
cleanup info.plist for ios14+
xiazhvera Jul 15, 2024
210e3b8
try using python3.7
xiazhvera Jul 15, 2024
85487c2
generate new dependency
xiazhvera Jul 15, 2024
dbb50fb
update requirement for python3.7
xiazhvera Jul 15, 2024
1c3f890
test for requests 2.31.0
xiazhvera Jul 15, 2024
5522c6e
update dependency
xiazhvera Jul 15, 2024
24f85d1
missing lib six
xiazhvera Jul 16, 2024
d6888b8
missing lib six
xiazhvera Jul 16, 2024
d610659
update lib3 version
xiazhvera Jul 16, 2024
12d6dac
add package
xiazhvera Jul 16, 2024
96e84ae
do pip upgrade
xiazhvera Jul 16, 2024
c98d115
setup veresion for pytest
xiazhvera Jul 16, 2024
99c6989
setup trio version
xiazhvera Jul 16, 2024
a0bdbd6
update capabilities for webdriver
xiazhvera Jul 16, 2024
f0a1fd6
use capabilties for webdriver
xiazhvera Jul 16, 2024
9e5cc0f
use a selenium 4.9
xiazhvera Jul 16, 2024
55b996b
use options for mqtt test
xiazhvera Jul 16, 2024
e183b4b
test on high avaliable pool
xiazhvera Jul 17, 2024
7897a5d
revert dependency for latest update
xiazhvera Jul 17, 2024
10dd2c3
clean up test args
xiazhvera Jul 17, 2024
49d7a9f
update background app
xiazhvera Jul 17, 2024
6834932
quick test for ios13
xiazhvera Jul 17, 2024
50ca46f
run on both 14+ and 13
xiazhvera Jul 17, 2024
0e2c7bc
install xcuitest
xiazhvera Jul 17, 2024
ae87a56
update to use crt account
xiazhvera Jul 17, 2024
dbc0001
update export option file
xiazhvera Jul 18, 2024
092be19
device farm in us-west-2; use appium 1
xiazhvera Jul 18, 2024
bd3ae01
set different appium version
xiazhvera Jul 18, 2024
77b0dcd
Merge branch 'mqtt_test_app' of https://github.com/awslabs/aws-crt-sw…
xiazhvera Jul 19, 2024
aad4d76
allow tls
sbSteveK Oct 1, 2024
8a7f52a
Merge branch 'mqtt_test_app' into secitem_bindings
sbSteveK Oct 1, 2024
f248f53
add setting of secitem options
sbSteveK Oct 2, 2024
0406905
aws-c-io nw_secitem branch
sbSteveK Oct 2, 2024
d261d8a
latest aws-c-io nw_secitem
sbSteveK Oct 2, 2024
08308e8
update aws-c-io
sbSteveK Oct 2, 2024
54ff235
use AWS_USE_SECITEM define
sbSteveK Oct 2, 2024
e19519a
add eventloop types to other platforms
sbSteveK Oct 2, 2024
b338b5d
lint error and differetiate between macOS and iOS/tvOS
sbSteveK Oct 2, 2024
9c2ba7f
add missing endif
sbSteveK Oct 2, 2024
827c071
try excluding dispatch queue related source files
sbSteveK Oct 2, 2024
e0dfcad
CRT changes
sbSteveK Oct 3, 2024
b507465
aws-c-io changes
sbSteveK Oct 3, 2024
a50380c
update aws-c-io changes
sbSteveK Oct 3, 2024
fb1b501
remove test error
sbSteveK Oct 3, 2024
1f3cee0
latest submodules
sbSteveK Oct 3, 2024
81946d3
update aws-c-io
sbSteveK Oct 4, 2024
78e5ac9
use latest aws-c-io
sbSteveK Oct 4, 2024
b9a6ed2
add defines in package.Swift
sbSteveK Oct 4, 2024
b2b21d1
latest aws-c-io
sbSteveK Oct 7, 2024
e6a9506
add defines to test and secitem options test
sbSteveK Oct 7, 2024
610e716
defines for swift test target
sbSteveK Oct 7, 2024
06451a0
add defines to tests in swift
sbSteveK Oct 7, 2024
9b177d2
remove watchOS testing
sbSteveK Oct 7, 2024
97ed422
pull latest aws-c-io changes
sbSteveK Oct 7, 2024
9a50b8d
update aws-c-io again
sbSteveK Oct 7, 2024
5e5bf33
update aws-c-io
sbSteveK Oct 16, 2024
0960792
merge latest main
sbSteveK Oct 31, 2024
52a458a
latest wip aws-c-io
sbSteveK Nov 5, 2024
e80b8a4
pull latest changes
sbSteveK Nov 5, 2024
2af72b8
update aws-c-io
sbSteveK Nov 6, 2024
aac5d89
updated submodules
sbSteveK Nov 8, 2024
1baa40b
update submodule
sbSteveK Nov 8, 2024
986c937
pull in latest changes from merged nw_socket
sbSteveK Nov 13, 2024
6e34fc8
latest aws-c-io
sbSteveK Nov 13, 2024
9a55e43
make HostResolver init public
sbSteveK Nov 13, 2024
2818d1d
Merge branch 'mqtt_test_app' of https://github.com/awslabs/aws-crt-sw…
xiazhvera Nov 30, 2024
468d6d6
update HostResolver to make init public
sbSteveK Dec 2, 2024
89a9431
test ios app
xiazhvera Dec 2, 2024
422dd0d
Merge branch 'secitem_bindings' of https://github.com/awslabs/aws-crt…
xiazhvera Dec 2, 2024
43ce156
test with device farm
xiazhvera Dec 2, 2024
5b843c8
figure out the folder
xiazhvera Dec 2, 2024
15ad1ed
switch to test folder
xiazhvera Dec 2, 2024
f83e1d8
list file....
xiazhvera Dec 2, 2024
cc9a31b
test device farm
xiazhvera Dec 2, 2024
ad90ebd
checkout source
xiazhvera Dec 2, 2024
47c41c4
update path
xiazhvera Dec 2, 2024
22778eb
use different certs and endpoint
xiazhvera Dec 2, 2024
fb0f2f3
setup aws-c-io
xiazhvera Dec 2, 2024
d19c527
fix credential file path
xiazhvera Dec 2, 2024
0106f8b
fix file name
xiazhvera Dec 2, 2024
0ac6f70
use the test info.plist file
xiazhvera Dec 2, 2024
14253c1
use apple account aws-common-runtime
xiazhvera Dec 2, 2024
8d2a095
update developer team id
xiazhvera Dec 2, 2024
dba5e48
force use PyYAML6.0.1
xiazhvera Dec 11, 2024
9f2f58d
test with fixed dependency version
xiazhvera Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 119 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,123 @@ jobs:
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}

ios-integration-test:
runs-on: macos-14
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
env:
DEVELOPER_DIR: /Applications/Xcode.app
XCODE_DESTINATION: 'OS X'
NSUnbufferedIO: YES
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.MOBILEPROVISION_BASE64 }}
KEYCHAIN_PASSWORD: ${{ secrets.TEST_KEYCHAIN_PASSWORD }}
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }}
- name: Install the Apple certificate and provisioning profile
run: |
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
PP_PATH=$RUNNER_TEMP/mqttclient.mobileprovision
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
aws s3 cp s3://aws-crt-test-stuff/iosTestApp.p12 $CERTIFICATE_PATH
aws s3 cp s3://aws-crt-test-stuff/aws-common-runtime.MqttClient.mobileprovision $PP_PATH
pkcs12_identity_pw=$(aws secretsmanager get-secret-value --region us-east-1 --secret-id "ci/ios/pkcs12_identity_password" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\")
# create temporary keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$pkcs12_identity_pw" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
# apply provisioning profile
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
- name : Setup iOS App Credentials
run : |
cd aws-crt-swift/Test/IntegrationTests/MqttClient/MqttClient
ENDPOINT=$(aws secretsmanager get-secret-value --region us-east-1 --secret-id "unit-test/endpoint" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\")
cert=$(aws secretsmanager get-secret-value --region us-east-1 --secret-id "unit-test/certificate" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\") && echo -e "$cert" > ./cert.pem
key=$(aws secretsmanager get-secret-value --region us-east-1 --secret-id "unit-test/privatekey" --query "SecretString" | cut -f2 -d":" | cut -f2 -d\") && echo -e "$key" > ./privatekey.pem
sed -i '' "s/<endpoint>/${ENDPOINT}/g" ContentView.swift
- name: Build Test App
run: |
xcode-select --print-path
pwd
cd aws-crt-swift/Test/IntegrationTests/MqttClient
pwd
xcodebuild -resolvePackageDependencies
echo "start build app"
xcodebuild -scheme "MqttClient" \
-archivePath $RUNNER_TEMP/MqttClient.xcarchive \
-configuration Release \
-destination generic/platform=iOS \
clean archive -allowProvisioningUpdates
- name: Export ipa
run: |
cd aws-crt-swift/Test/IntegrationTests/MqttClient
aws s3 cp s3://aws-crt-test-stuff/ExportOptions.plist ExportOptions.plist
xcodebuild -exportArchive -archivePath $RUNNER_TEMP/MqttClient.xcarchive -exportOptionsPlist ExportOptions.plist -exportPath output
cd output
ls
- name: Setup Device Farm test file and environment
# Device Farm Instructions: https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-appium.html
run: |
cd aws-crt-swift/Test/IntegrationTests/MqttClient
pwd
pip install virtualenv
virtualenv --help
virtualenv workspace
cd workspace
source bin/activate
pip install -r ../DeviceFarmScript/requirements.txt
# Create a test bundle folder for upload
mkdir tests
cp ../DeviceFarmScript/mqtt_ios_test.py tests/
find tests/
py.test --collect-only tests/
cd tests/
find . -name '__pycache__' -type d -exec rm -r {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
cd ..
pip freeze > requirements.txt
zip -r test_bundle.zip tests/ requirements.txt
- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: us-west-2 # Device Farm only available on us-west-2
- name: Execute device farm iOS Highly Available
run: |
cd aws-crt-swift/Test/IntegrationTests/MqttClient
pip install -r ./DeviceFarmScript/requirements.txt
ls
python ./DeviceFarmScript/run_ios_ci.py \
--run_id ${{ github.run_id }} \
--run_attempt ${{ github.run_attempt }} \
--project_arn $(aws secretsmanager get-secret-value --region us-east-1 --secret-id "ci/DeviceFarm/iOSProjectArn" --query "SecretString" | cut -f2 -d\") \
--device_pool_arn $(aws secretsmanager get-secret-value --region us-east-1 --secret-id "ci/DeviceFarm/iOSHighlyAvailablePool" --query "SecretString" | cut -f2 -d\") \
--app_file_path ./output/MqttClient.ipa \
--test_file_path ./workspace/test_bundle.zip \
--test_spec_file_path ./DeviceFarmScript/test_spec.yml
- name: Execute device farm iOS 13
run: |
cd aws-crt-swift/Test/IntegrationTests/MqttClient
pip install -r ./DeviceFarmScript/requirements.txt
ls
python ./DeviceFarmScript/run_ios_ci.py \
--run_id ${{ github.run_id }} \
--run_attempt ${{ github.run_attempt }} \
--project_arn $(aws secretsmanager get-secret-value --region us-east-1 --secret-id "ci/DeviceFarm/iOSProjectArn" --query "SecretString" | cut -f2 -d\") \
--device_pool_arn $(aws secretsmanager get-secret-value --region us-east-1 --secret-id "ci/DeviceFarm/iOS13PoolArn" --query "SecretString" | cut -f2 -d\") \
--app_file_path ./output/MqttClient.ipa \
--test_file_path ./workspace/test_bundle.zip \
--test_spec_file_path ./DeviceFarmScript/test_spec.yml

devices:
runs-on: ${{ matrix.runner }}
env:
Expand All @@ -70,7 +187,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# This matrix runs tests on iOS, tvOS & watchOS, on oldest & newest supported Xcodes
# This matrix runs tests on iOS and tvOS on oldest & newest supported Xcodes
runner:
- macos-12 # x64
- macos-13 # x64
Expand All @@ -81,9 +198,7 @@ jobs:
[{ os: ios, destination: 'iOS Simulator,OS=16.1,name=iPhone 14'},
{ os: ios, destination: 'iOS Simulator,OS=17.2,name=iPhone 15'},
{ os: tvos, destination: 'tvOS Simulator,OS=16.1,name=Apple TV 4K (3rd generation) (at 1080p)'},
{ os: tvos, destination: 'tvOS Simulator,OS=17.2,name=Apple TV 4K (3rd generation) (at 1080p)'},
{ os: watchos, destination: 'watchOS Simulator,OS=10.2,name=Apple Watch SE (40mm) (2nd generation)'},
{ os: watchos, destination: 'watchOS Simulator,OS=9.1,name=Apple Watch Series 5 (40mm)'}]
{ os: tvos, destination: 'tvOS Simulator,OS=17.2,name=Apple TV 4K (3rd generation) (at 1080p)'}]
xcode:
- Xcode_14.1
- Xcode_15.2
Expand All @@ -110,10 +225,6 @@ jobs:
xcode: Xcode_14.1
- target: { os: ios, destination: 'iOS Simulator,OS=17.2,name=iPhone 15'}
xcode: Xcode_14.1
- target: { os: watchos, destination: 'watchOS Simulator,OS=10.2,name=Apple Watch SE (40mm) (2nd generation)'}
xcode: Xcode_14.1
- target: { os: watchos, destination: 'watchOS Simulator,OS=9.1,name=Apple Watch Series 5 (40mm)'}
xcode: Xcode_15.2
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
Expand Down
18 changes: 17 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ let cSettings: [CSetting] = [
.define("AWS_APPSTORE_SAFE"),
]

/// Store any defines that will be used by Swift Tests in swiftTestSettings
var swiftTestSettings: [SwiftSetting] = []

//////////////////////////////////////////////////////////////////////
/// Configure C targets.
/// Note: We can not use unsafe flags because SwiftPM makes the target ineligible for use by other packages.
Expand Down Expand Up @@ -124,14 +127,26 @@ awsCIoPlatformExcludes.append("source/posix")
awsCIoPlatformExcludes.append("source/linux")
awsCIoPlatformExcludes.append("source/s2n")
awsCIoPlatformExcludes.append("source/darwin")
cSettingsIO.append(.define("AWS_ENABLE_IO_COMPLETION_PORTS"))
swiftTestSettings.append(.define("AWS_ENABLE_IO_COMPLETION_PORTS"))
#elseif os(Linux)
awsCIoPlatformExcludes.append("source/windows")
awsCIoPlatformExcludes.append("source/bsd")
awsCIoPlatformExcludes.append("source/darwin")
cSettingsIO.append(.define("AWS_ENABLE_EPOLL"))
swiftTestSettings.append(.define("AWS_ENABLE_EPOLL"))
#else // macOS, iOS, watchOS, tvOS
awsCIoPlatformExcludes.append("source/windows")
awsCIoPlatformExcludes.append("source/linux")
awsCIoPlatformExcludes.append("source/s2n")
cSettingsIO.append(.define("__APPLE__"))
cSettingsIO.append(.define("AWS_ENABLE_DISPATCH_QUEUE", .when(platforms: [.iOS, .tvOS, .macOS])))
cSettingsIO.append(.define("AWS_USE_SECITEM", .when(platforms: [.iOS, .tvOS])))
cSettingsIO.append(.define("AWS_ENABLE_KQUEUE", .when(platforms: [.macOS])))
swiftTestSettings.append(.define("__APPLE__"))
swiftTestSettings.append(.define("AWS_ENABLE_DISPATCH_QUEUE", .when(platforms: [.iOS, .tvOS, .macOS])))
swiftTestSettings.append(.define("AWS_USE_SECITEM", .when(platforms: [.macOS, .iOS, .tvOS])))
swiftTestSettings.append(.define("AWS_ENABLE_KQUEUE", .when(platforms: [.macOS])))
#endif

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -304,7 +319,8 @@ packageTargets.append(contentsOf: [
path: "Test/AwsCommonRuntimeKitTests",
resources: [
.process("Resources")
]
],
swiftSettings: swiftTestSettings
),
.executableTarget(
name: "Elasticurl",
Expand Down
5 changes: 1 addition & 4 deletions Source/AwsCommonRuntimeKit/io/HostResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public class HostResolver: HostResolverProtocol {
shutdownCallback: shutdownCallback)
}

init(eventLoopGroup: EventLoopGroup,
maxHosts: Int,
maxTTL: Int,
shutdownCallback: ShutdownCallback? = nil) throws {
public init(eventLoopGroup: EventLoopGroup, maxHosts: Int, maxTTL: Int, shutdownCallback: ShutdownCallback? = nil) throws {
let shutdownCallbackCore = ShutdownCallbackCore(shutdownCallback)
let getRawValue: () -> UnsafeMutablePointer<aws_host_resolver>? = {
withUnsafePointer(to: shutdownCallbackCore.getRetainedShutdownOptions()) { shutdownCallbackCorePointer in
Expand Down
20 changes: 18 additions & 2 deletions Source/AwsCommonRuntimeKit/io/TLSContextOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TLSContextOptions: CStruct {
public static func makeMTLS(
certificateData: Data,
privateKeyData: Data) throws -> TLSContextOptions {
#if os(tvOS) || os(iOS) || os(watchOS)
#if os(watchOS)
throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_PLATFORM_NOT_SUPPORTED.rawValue))
#endif
return try TLSContextOptions(certificateData: certificateData, privateKeyData: privateKeyData)
Expand All @@ -55,7 +55,7 @@ public class TLSContextOptions: CStruct {
public static func makeMTLS(
certificatePath: String,
privateKeyPath: String) throws -> TLSContextOptions {
#if os(tvOS) || os(iOS) || os(watchOS)
#if os(watchOS)
throw CommonRunTimeError.crtError(CRTError(code: AWS_ERROR_PLATFORM_NOT_SUPPORTED.rawValue))
#endif
return try TLSContextOptions(certificatePath: certificatePath, privateKeyPath: privateKeyPath)
Expand Down Expand Up @@ -126,6 +126,22 @@ public class TLSContextOptions: CStruct {
public func setMinimumTLSVersion(_ tlsVersion: TLSVersion) {
aws_tls_ctx_options_set_minimum_tls_version(rawValue, aws_tls_versions(rawValue: tlsVersion.rawValue))
}

/// Updates TLSContextOptions to use specified options when importing certificate and key into keychain.
///
/// NOTE: This only works on Apple devices using Apple keychain via Secitem.. The library is currently only tested on iOS.
///
/// - Parameters:
/// - certLabel: Human readable label to apply to certificate being imported into keychain.
/// - keyLabel: Human readable label to apply to key being imported into keychain.
/// - Throws: CommonRuntimeError.crtError
public func setSecitemLabels(certLabel: String? = nil, keyLabel: String? = nil) throws {
let secitemOptions = TLSSecitemOptions(certLabel: certLabel, keyLabel: keyLabel)

if aws_tls_ctx_options_set_secitem_options(rawValue, secitemOptions.rawValue) != AWS_OP_SUCCESS {
throw CommonRunTimeError.crtError(CRTError.makeFromLastError())
}
}

typealias RawType = aws_tls_ctx_options
func withCStruct<Result>(_ body: (aws_tls_ctx_options) -> Result) -> Result {
Expand Down
37 changes: 37 additions & 0 deletions Source/AwsCommonRuntimeKit/io/TLSSecitemOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.

import AwsCIo

public class TLSSecitemOptions: CStruct {
var rawValue: UnsafeMutablePointer<aws_secitem_options>

public init(
certLabel: String? = nil,
keyLabel: String? = nil) {

self.rawValue = allocator.allocate(capacity: 1)

self.rawValue.pointee.cert_label = certLabel?.withByteCursorPointer { certLabelCursorPointer in
aws_string_new_from_cursor(
allocator.rawValue,
certLabelCursorPointer)
}

self.rawValue.pointee.key_label = keyLabel?.withByteCursorPointer { keyLabelCursorPointer in
aws_string_new_from_cursor(
allocator.rawValue,
keyLabelCursorPointer)
}
}

typealias RawType = aws_secitem_options
func withCStruct<Result>(_ body: (aws_secitem_options) -> Result) -> Result {
return body(rawValue.pointee)
}

deinit {
aws_tls_secitem_options_clean_up(rawValue)
allocator.release(rawValue)
}
}
16 changes: 16 additions & 0 deletions Test/AwsCommonRuntimeKitTests/io/TLSContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,20 @@ class TLSContextTests: XCBaseTestCase {
_ = TLSConnectionOptions(context: context)
}
#endif

#if AWS_USE_SECITEM
func testCreateTlsContextWithSecitemOptions() 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)
try options.setSecitemLabels(certLabel: "TEST_CERT_LABEL", keyLabel: "TEST_KEY_LABEL")

let context = try TLSContext(options:options, mode: .client)
_ = TLSConnectionOptions(context: context)
}
#endif
}
56 changes: 56 additions & 0 deletions Test/IntegrationTests/MqttClient/DeviceFarmScript/mqtt_ios_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0.
"""
import pytest
from time import sleep

from appium import webdriver
from appium.options.ios import XCUITestOptions
from appium.webdriver.common.appiumby import AppiumBy
from selenium.common.exceptions import NoSuchElementException

capabilities = dict(
platformName='ios',
automationName='xcuitest',
deviceName='iPhone',
bundleId='aws-common-runtime.MqttClient',
language='en',
locale='US',
)

appium_server_url = 'http://0.0.0.0:4723/wd/hub'

class TestMqttIOS:
def setup_method(self):
self.driver = webdriver.Remote(appium_server_url, options=XCUITestOptions().load_capabilities(capabilities))
self.driver.implicitly_wait(10)

def teardown_method(self):
if self.driver:
self.driver.quit()

@pytest.mark.parametrize("event_loop_tests", [
"Background Process"
])

def test_mqtt(self, event_loop_tests):
sleep(3)
self.perform_click_element('Setup Client and Start')
# Sleep to make sure the connection is finished
sleep(10)
# put the application in background
self.driver.background_app(-1)
# Wait to see if the connection is interrupted
sleep(15)

def perform_click_element(self, element_id):
try:
element = self.driver.find_element(by=AppiumBy.ID, value=element_id)
element.click()
sleep(2)
except NoSuchElementException:
pytest.skip(f"Element with ID '{element_id}' not found. Skipped the test")

if __name__ == '__main__':
TestMqttIOS.test_mqtt()
12 changes: 12 additions & 0 deletions Test/IntegrationTests/MqttClient/DeviceFarmScript/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
packaging==24.0
Appium-Python-Client==2.11.0
pytest==7.4.3
boto3==1.28.1
urllib3==1.26.18
requests==2.28.0
PyYAML==6.0.1
pytest-metadata==3.0.0
pytest-html==3.2.0
selenium==4.9.0
pluggy==1.2.0
trio==0.22.2
Loading
Loading