Module: Calabash::Cucumber::KeychainHelpers

Included in:
Operations
Defined in:
lib/calabash-cucumber/keychain_helpers.rb

Overview

KeychainHelpers provide a helpers to access the iOS keychain.

Simulator Note

When running on the simulator, the keychain is not sandboxed between applications like it is on a real device. These methods will return keychain records from all applications on the simulator, which may result in strange behavior if you aren't expecting it.

Instance Method Summary collapse

Instance Method Details

#keychain_accountsArray<Hash>

Asks the keychain for all of the account records.

The hash keys are defined by the SSKeychain library.

The following keys are the most commonly useful:

svce #=> the service
acct #=> the account (often a username)
cdat #=> the creation date
mdat #=> the last-modified date

Returns:

  • (Array<Hash>)

    of all account records saved in the iOS keychain.

Raises:

  • (RuntimeError)

    if http request does not report success

See Also:



64
65
66
# File 'lib/calabash-cucumber/keychain_helpers.rb', line 64

def keychain_accounts
  _keychain_get
end

#keychain_accounts_for_service(service) ⇒ Array<Hash>

Returns an list of all account records saved in the iOS keychain filtered by service.

Parameters:

  • service (String)

    the service whose accounts you are requesting

Returns:

  • (Array<Hash>)

    a list all account records filtered by service.

Raises:

  • (RuntimeError)

    if http request does not report success

See Also:



76
77
78
# File 'lib/calabash-cucumber/keychain_helpers.rb', line 76

def keychain_accounts_for_service(service)
  _keychain_get({:service => service})
end

#keychain_clearnil

On the iOS Simulator this clears all keychain entries for all applications.

On a physical device, this will clear all entries for the target application.

Returns:

  • (nil)

Raises:

  • (RuntimeError)

    if http request does not report success



134
135
136
# File 'lib/calabash-cucumber/keychain_helpers.rb', line 134

def keychain_clear
  _keychain_post
end

#keychain_clear_accounts_for_service(service) ⇒ nil

Clear all entries in the keychain restricted to a single service.

Parameters:

  • service (String)

    filters which accounts should be cleared.

Returns:

  • (nil)

Raises:

  • (RuntimeError)

    if http request does not report success



144
145
146
# File 'lib/calabash-cucumber/keychain_helpers.rb', line 144

def keychain_clear_accounts_for_service(service)
  _keychain_post({:service => service})
end

#keychain_delete_password(service, account) ⇒ Object

Delete a single keychain record for the given service and account pair.

Parameters:

  • service (String)

    filters which accounts should be cleared.

  • account (String)

    filters which account to clear

Raises:

  • (RuntimeError)

    if http request does not report success



155
156
157
# File 'lib/calabash-cucumber/keychain_helpers.rb', line 155

def keychain_delete_password(service, )
  _keychain_post(:service => service, :account => )
end

#keychain_password(service, account) ⇒ String, Array<Hash>

Note:

IMPORTANT On the XTC, the password cannot returned as plain text. When using this keychain_password in your steps you can condition on the XTC environment using xamarin_test_cloud?

Ask the keychain for an account password.

Returns:

  • (String, Array<Hash>)

    password stored in keychain for service and account. NB on the XTC this returns an Array with one Hash.

Raises:

  • (RuntimeError)

    if http request does not report success

  • (RuntimeError)

    if service and account pair does not contain a password

See Also:



96
97
98
# File 'lib/calabash-cucumber/keychain_helpers.rb', line 96

def keychain_password(service, )
  _keychain_get({:service => service, :account => }).first
end

#keychain_set_password(service, account, password) ⇒ Object

Set the password for a given service and account pair.

Parameters:

  • service (String)

    which service to update

  • account (String)

    which account to update

  • password (String)

    which password to set

Returns:

  • nil

Raises:

  • (RuntimeError)

    if http request does not report success



167
168
169
# File 'lib/calabash-cucumber/keychain_helpers.rb', line 167

def keychain_set_password(service, , password)
  _keychain_post(:service => service, :account => , :password => password)
end