Commit 249c8c83 authored by Sergey Gernyak's avatar Sergey Gernyak

REF: session manager is use account subsystem

parent eb430bf3
......@@ -12,12 +12,12 @@ module BetfairApiNgRails
end
end
def session_requester
def session_requester(account)
create_http_requester(LOGIN_URL, false).tap do |req|
req.set_ssl_files Api::Config.ssl_crt_filepath, Api::Config.ssl_key_filepath
req.set_ssl_files account.crt_filepath, account.key_filepath
req.set_request_headers SESSION_REQUEST_HEADERS
req.set_auth_headers Api::Config.application_key
req.set_form_data "username" => Api::Config.username, "password" => Api::Config.password
req.set_auth_headers account.app_key
req.set_form_data "username" => account.username, "password" => account.password
end
end
......
......@@ -48,7 +48,7 @@ module BetfairApiNgRails
end
def http_requester
@_http_requester ||= Api::Http::Factory.session_requester
@_http_requester ||= Api::Http::Factory.session_requester account
end
end
end
......
......@@ -41,4 +41,35 @@ describe BetfairApiNgRails::Api::SessionManager do
session_manager.expire_ssoid account
end
end
end
describe BetfairApiNgRails::Api::SessionManager::SsoidRequester do
subject(:requester) { described_class.new(account) }
let(:username) { 'user001' }
let(:account) { BetfairApiNgRails::Account.new(username, 'password', '3cnt4ngt8oh3co', 'crt', 'key') }
let(:http_requester) { double(:http_requester, do_request: login_response) }
let(:login_response) do
double(:login_response, session_token: session_token)
end
let(:session_token) { 'some_session_token_str' }
before do
allow(BetfairApiNgRails::Api::Http::Factory).to receive(:session_requester)
.with(account)
.and_return http_requester
end
describe '#get' do
it 'returns fetched ssoid' do
expect(requester.get).to eq session_token
end
it 'stores fetched ssoid in registry' do
requester.get
expect(BetfairApiNgRails.account_session_manager.sessions.count).to eq 1
end
end
end
require 'spec_helper'
describe BetfairApiNgRails::Api::Http::Factory do
let(:account) do
BetfairApiNgRails::Account.new(
'user001',
'password',
'app_key',
'crt_filepath',
'key_filepath'
)
end
let(:requester) { double(:requester) }
subject(:factory) { described_class }
describe '.session_requester' do
before do
expect(factory).to receive(:create_http_requester)
.with(BetfairApiNgRails::Api::Constants::LOGIN_URL, false)
.and_return(requester)
end
it 'settings up requester for session' do
expect(requester).to receive(:set_ssl_files).with 'crt_filepath', 'key_filepath'
expect(requester).to receive(:set_request_headers)
expect(requester).to receive(:set_auth_headers).with 'app_key'
expect(requester).to receive(:set_form_data)
.with('username' => 'user001', 'password' => 'password')
factory.session_requester account
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment