Permalink
Browse files

Add support for generating the auth tokens necessary for no-login links

  • Loading branch information...
rtyler committed Aug 6, 2012
1 parent f9b4716 commit 8c56db4864d4b0105cab59bc6017a56003b6a797
Showing with 19 additions and 2 deletions.
  1. +8 −0 lib/saucetv/api.rb
  2. +0 −1 lib/saucetv/app.rb
  3. +11 −1 spec/api_spec.rb
View
@@ -1,4 +1,5 @@
require 'rubygems'
+require 'hmac-md5'
require 'httparty'
module SauceTV
@@ -12,6 +13,7 @@ class API
def initialize(username, api_key)
@username = username
+ @api_key = api_key
@auth = {:username => username, :password => api_key}
end
@@ -66,5 +68,11 @@ def info_for(job_id)
return response.parsed_response
end
+
+ def auth_token_for(job_id)
+ h = HMAC::MD5.new("#{@username}:#{@api_key}")
+ h << job_id
+ h.hexdigest
+ end
end
end
View
@@ -1,7 +1,6 @@
require 'rubygems'
require 'haml'
-require 'hmac'
require 'sinatra'
require 'saucetv/api'
require 'saucetv/errors'
View
@@ -2,7 +2,9 @@
describe SauceTV::API do
- subject { SauceTV::API.new('rspec', 'rspec') }
+ let(:username) { 'rspec' }
+ let(:api_key) { 'rspec' }
+ subject { SauceTV::API.new(username, api_key) }
describe :format do
it 'should always be :json' do
@@ -67,6 +69,14 @@
end
end
end
+
+ describe :auth_token_for do
+ let(:job_id) { 'rspec_jobid' }
+
+ it 'should generate the right token for the ID, username and API key' do
+ subject.auth_token_for(job_id).should == 'eab6d962d96a9abf2b8e770f64a70e35'
+ end
+ end
end

0 comments on commit 8c56db4

Please sign in to comment.