spec/fetcher_spec.rb in lastpass-1.3.0 vs spec/fetcher_spec.rb in lastpass-1.4.0

- old
+ new

@@ -21,16 +21,35 @@ xml: 1, username: username, hash: hash, iterations: key_iteration_count} } + let(:device_id) { "492378378052455" } + let(:login_post_data_with_device_id) { login_post_data.merge({imei: device_id}) } + let(:google_authenticator_code) { "123456" } let(:yubikey_password) { "emdbwzemyisymdnevznyqhqnklaqheaxszzvtnxjrmkb" } - let(:login_post_data_with_google_authenticator_code) { login_post_data.merge({otp: google_authenticator_code})} + let(:login_post_data_with_google_authenticator_code) { login_post_data.merge({otp: google_authenticator_code}) } let(:login_post_data_with_yubikey_password) { login_post_data.merge({otp: yubikey_password}) } + describe ".logout" do + it "makes a GET request" do + web_client = double "web_client" + expect(web_client).to receive(:get) + .with("https://lastpass.com/logout.php?mobile=1", cookies: {"PHPSESSID" => session_id}) + .and_return(http_ok "") + LastPass::Fetcher.logout session, web_client + end + + it "raises an exception on HTTP error" do + expect { + LastPass::Fetcher.logout session, double("web_client", get: http_error) + }.to raise_error LastPass::NetworkError + end + end + describe ".request_iteration_count" do it "makes a POST request" do expect(web_client = double("web_client")).to receive(:post) .with("https://lastpass.com/iterations.php", query: {email: username}) .and_return(http_ok(key_iteration_count.to_s)) @@ -73,33 +92,38 @@ }.to raise_error LastPass::InvalidResponseError, "Key iteration count is not positive" end end describe ".request_login" do - def verify_post_request multifactor_password, post_data + def verify_post_request multifactor_password, device_id, post_data web_client = double("web_client") expect(web_client).to receive(:post) .with("https://lastpass.com/login.php", format: :xml, body: post_data) .and_return(http_ok("ok" => {"sessionid" => session_id})) LastPass::Fetcher.request_login username, password, key_iteration_count, multifactor_password, + device_id, web_client end it "makes a POST request" do - verify_post_request nil, login_post_data + verify_post_request nil, nil, login_post_data end + it "makes a POST request with device id" do + verify_post_request nil, device_id, login_post_data_with_device_id + end + it "makes a POST request with Google Authenticator code" do - verify_post_request google_authenticator_code, login_post_data_with_google_authenticator_code + verify_post_request google_authenticator_code, nil, login_post_data_with_google_authenticator_code end it "makes a POST request with Yubikey password" do - verify_post_request yubikey_password, login_post_data_with_yubikey_password + verify_post_request yubikey_password, nil, login_post_data_with_yubikey_password end it "returns a session" do expect(request_login_with_xml "<ok sessionid='#{session_id}' />").to eq session end @@ -274,9 +298,10 @@ def request_login_with_response response LastPass::Fetcher.request_login username, password, key_iteration_count, + nil, nil, double("web_client", post: response) end end