Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement warning text when the recent_jobs API call returns an autho…

…rization error
  • Loading branch information...
commit 12e5ce716e2638091098bab625a524b52fdc14df 1 parent b763f86
@rtyler authored
View
2  features/step_definitions/watch_steps.rb
@@ -36,5 +36,5 @@
end
Then /^I should be told my credentials are invalid$/ do
- pending # express the regexp above with the code you wish you had
+ page.should have_content('Your username or API key is invalid')
end
View
1  features/watch.feature
@@ -10,7 +10,6 @@ Feature: Watch recorded job runs
When I try to watch videos
Then I should be prompted to log in with my username and API key
- @wip
Scenario: With invalid user credentials
Given I have an invalid Sauce Labs username or API key
When I try to watch videos
View
6 lib/saucetv/api.rb
@@ -30,12 +30,16 @@ def format
def recent_jobs
begin
- response = get("/v1/#{username}/jobs")
+ response = get("/v1/#{username}/jobs?full=true")
rescue Timeout::Error => e
puts "A call to SauceTV::API#recent_jobs timed out (#{e.inspect})"
return []
end
+ if response.code == 401
+ raise SauceTV::InvalidUserCredentials
+ end
+
unless response.code == 200
return []
end
View
12 lib/saucetv/app.rb
@@ -3,6 +3,7 @@
require 'haml'
require 'sinatra'
require 'saucetv/api'
+require 'saucetv/errors'
module SauceTV
class Application < Sinatra::Base
@@ -17,7 +18,8 @@ def authenticated?
end
get '/login' do
- haml :login
+ invalid = !(params['invalid'].nil?)
+ haml :login, :locals => {:invalid => invalid}
end
post '/login' do
@@ -32,8 +34,14 @@ def authenticated?
end
api = SauceTV::API.new(session[:username], session[:api_key])
+ jobs = []
+
+ begin
+ jobs = api.recent_jobs
+ rescue SauceTV::InvalidUserCredentials
+ redirect to('/login?invalid=true')
+ end
- jobs = api.recent_jobs
haml :watch, :locals => {
:username => session[:username],
:jobs => jobs
View
24 lib/saucetv/views/login.haml
@@ -3,13 +3,19 @@
%title
SauceLabs.tv
%body
- Please log in with your username and API key
+ - if invalid
+ %p
+ Your username or API key is invalid
- %form{:method => 'POST', :action => '/login'}
- %label
- Sauce Labs Username:
- %input{:name => 'username'}
- %label
- Sauce Labs API Key:
- %input{:name => 'api_key', :type => 'password'}
- %input{:type => 'submit', :value => 'Log in'}
+ %center
+ %h1
+ Please log in with your username and API key
+
+ %form{:method => 'POST', :action => '/login'}
+ %label
+ Sauce Labs Username:
+ %input{:name => 'username'}
+ %label
+ Sauce Labs API Key:
+ %input{:name => 'api_key', :type => 'password'}
+ %input{:type => 'submit', :value => 'Log in'}
Please sign in to comment.
Something went wrong with that request. Please try again.