in sdk/swift/TeaclaveClientSDK/TeaclaveClientSDKTests/TeaclaveClientSDKTests.swift [74:170]
func testBuiltinPasswordCheck() throws {
let user0_client = AuthenticationClient(
address: authentication_service_address,
enclave_info_path: enclave_info_path,
as_root_ca_cert_path: as_root_ca_cert_path
)!
let user0_token = try user0_client.login(id: "admin", password: "teaclave").get()
let user0_frontend_client = FrontendClient(
address: frontend_service_address,
enclave_info_path: enclave_info_path,
as_root_ca_cert_path: as_root_ca_cert_path
)!
try user0_frontend_client.set_credential(id: "user0", token: user0_token).get()
let register_function_request = RegisterFunctionRequest(
name: "builtin-password-check",
description: "Check whether a password is exposed.",
executor_type: "builtin",
payload: [],
arguments: [],
inputs: [
["name": "password", "description": "Client 0's data."],
["name": "exposed_passwords", "description": "Client 1's data."]
],
outputs: []
)
let response = try user0_frontend_client.register_function(with: register_function_request).get()
let function_id = response.function_id
let create_task_request = CreateTaskRequest(
function_id: function_id,
function_arguments: "{}",
executor: "builtin",
inputs_ownership: [
OwnerList(data_name: "password", uids: ["user0"]),
OwnerList(data_name: "exposed_passwords", uids: ["user1"]),
],
outputs_ownership: []
)
let task_id = try user0_frontend_client.create_task(with: create_task_request).get().task_id
let iv = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
let key = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
let register_input_file_request = RegisterInputFileRequest(
url: "data:text/plain;base64,c+mpvRfZ0fboR0j3rTgOGDBiubSzlCt9",
cmac: [0xe8, 0x47, 0x48, 0xf7, 0xad, 0x38, 0x0e, 0x18, 0x30, 0x62, 0xb9, 0xb4, 0xb3, 0x94, 0x2b, 0x7d],
crypto_info: CryptoInfo(schema: "aes-gcm-128", key: key, iv: iv)
)
let user0_data_id = try user0_frontend_client.register_input_file(with: register_input_file_request).get().data_id
let user0_assign_data_request = AssignDataRequest(
task_id: task_id,
inputs: [DataMap(data_name: "password", data_id: user0_data_id)],
outputs: []
)
try user0_frontend_client.assign_data(with: user0_assign_data_request).get()
let user1_client = AuthenticationClient(
address: authentication_service_address,
enclave_info_path: enclave_info_path,
as_root_ca_cert_path: as_root_ca_cert_path
)!
let user1_token = try user1_client.login(id: "admin", password: "teaclave").get()
let user1_frontend_client = FrontendClient(
address: frontend_service_address,
enclave_info_path: enclave_info_path,
as_root_ca_cert_path: as_root_ca_cert_path
)!
try user1_frontend_client.set_credential(id: "user1", token: user1_token).get()
let user1_register_input_file_request = RegisterInputFileRequest(
url: "http://teaclave-file-service:6789/fixtures/functions/password_check/exposed_passwords.txt.enc",
cmac: [0x42, 0xb1, 0x6c, 0x29, 0xed, 0xeb, 0x9e, 0xe0, 0xe4, 0xd2, 0x19, 0xf3, 0xb5, 0x39, 0x59, 0x46],
crypto_info: CryptoInfo(schema: "teaclave-file-128", key: key, iv: [])
)
let user1_data_id = try user1_frontend_client.register_input_file(with: user1_register_input_file_request).get().data_id
let user1_assign_data_request = AssignDataRequest(
task_id: task_id,
inputs: [DataMap(data_name: "exposed_passwords", data_id: user1_data_id)],
outputs: []
)
try user1_frontend_client.assign_data(with: user1_assign_data_request).get()
try user0_frontend_client.approve_task(task_id: task_id).get()
try user1_frontend_client.approve_task(task_id: task_id).get()
try user0_frontend_client.invoke_task(task_id: task_id).get()
let result = try user0_frontend_client.get_task_result(task_id: task_id).get()
XCTAssert(result == "true")
}