Skip to content

Commit

Permalink
Share Test App setup with other client libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworiordan committed Apr 13, 2015
1 parent aa4a30d commit a0b9081
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 53 deletions.
2 changes: 1 addition & 1 deletion lib/submodules/ably-common
25 changes: 10 additions & 15 deletions spec/acceptance/rest/presence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@

# Encrypted fixtures need encryption details or an error will be raised
let(:cipher_details) { TestApp::APP_SPEC_CIPHER }
let(:algorithm) { cipher_details.fetch(:algorithm).upcase }
let(:mode) { cipher_details.fetch(:mode).upcase }
let(:key_length) { cipher_details.fetch(:keylength) }
let(:secret_key) { Base64.decode64(cipher_details.fetch(:key)) }
let(:iv) { Base64.decode64(cipher_details.fetch(:iv)) }
let(:algorithm) { cipher_details.fetch('algorithm').upcase }
let(:mode) { cipher_details.fetch('mode').upcase }
let(:key_length) { cipher_details.fetch('keylength') }
let(:secret_key) { Base64.decode64(cipher_details.fetch('key')) }
let(:iv) { Base64.decode64(cipher_details.fetch('iv')) }

let(:cipher_options) { { key: secret_key, algorithm: algorithm, mode: mode, key_length: key_length, iv: iv } }
let(:fixtures_channel) { client.channel('persisted:presence_fixtures', encrypted: true, cipher_params: cipher_options, iv: iv) }

context 'tested against presence fixture data set up in test app' do
describe '#get' do
before(:context) do
# When this test is run as a part of a test suite, the presence data injected in the test app may have expired
reload_test_app
end
before(:context) do
# When this test is run as a part of a test suite, the presence data injected in the test app may have expired
reload_test_app
end

describe '#get' do
let(:presence) { fixtures_channel.presence.get }

it 'returns current members on the channel with their action set to :present' do
Expand All @@ -62,11 +62,6 @@
end

describe '#history' do
before(:context) do
# When this test is run as a part of a test suite, the presence data injected in the test app may have expired
reload_test_app
end

let(:presence_history) { fixtures_channel.presence.history }

it 'returns recent presence activity' do
Expand Down
46 changes: 9 additions & 37 deletions spec/support/test_app.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,15 @@
require 'singleton'

class TestApp
APP_SPEC = {
'keys' => [
{},
{
'capability' => '{ "cansubscribe:*":["subscribe"], "canpublish:*":["publish"], "canpublish:andpresence":["presence","publish"] }'
}
],
'namespaces' => [
{ 'id' => 'persisted', 'persisted' => true }
],
'channels' => [
{
'name' => 'persisted:presence_fixtures',
'presence' => [
{ 'clientId' => 'client_bool', 'data' => 'true' },
{ 'clientId' => 'client_int', 'data' => '24' },
{ 'clientId' => 'client_string', 'data' => 'This is a string clientData payload' },
{ 'clientId' => 'client_json', 'data' => '{ "test" => \'This is a JSONObject clientData payload\'}' },
{ 'clientId' => 'client_decoded', 'data' => '{"example":{"json":"Object"}}', 'encoding' => 'json/utf-8' },
{
'clientId' => 'client_encoded',
'data' => 'HO4cYSP8LybPYBPZPHQOtuD53yrD3YV3NBoTEYBh4U0N1QXHbtkfsDfTspKeLQFt',
'encoding' => 'json/utf-8/cipher+aes-128-cbc/base64'
}
]
}
]
}

# Cipher details used for client_encoded presence data
APP_SPEC_CIPHER = {
algorithm: 'aes',
mode: 'cbc',
keylength: 128,
key: 'WUP6u0K7MXI5Zeo0VppPwg==',
iv: 'HO4cYSP8LybPYBPZPHQOtg==',
}
TEST_RESOURCES_PATH = File.expand_path('../../../lib/submodules/ably-common/test-resources', __FILE__)

# App configuration for test app
# See https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json
APP_SPEC = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['post_apps']

# Cipher details used for client_encoded presence data in test app
# See https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json
APP_SPEC_CIPHER = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['cipher']

# If an app has already been created and we need a new app, create a new test app
# This is sometimes needed when a test needs to be isolated from any other tests
Expand Down

0 comments on commit a0b9081

Please sign in to comment.