Add support for generating the auth tokens necessary for no-login links
This commit is contained in:
parent
f9b4716d35
commit
8c56db4864
|
@ -1,4 +1,5 @@
|
|||
require 'rubygems'
|
||||
require 'hmac-md5'
|
||||
require 'httparty'
|
||||
|
||||
module SauceTV
|
||||
|
@ -12,6 +13,7 @@ module SauceTV
|
|||
|
||||
def initialize(username, api_key)
|
||||
@username = username
|
||||
@api_key = api_key
|
||||
@auth = {:username => username, :password => api_key}
|
||||
end
|
||||
|
||||
|
@ -66,5 +68,11 @@ module SauceTV
|
|||
|
||||
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
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
require 'rubygems'
|
||||
|
||||
require 'haml'
|
||||
require 'hmac'
|
||||
require 'sinatra'
|
||||
require 'saucetv/api'
|
||||
require 'saucetv/errors'
|
||||
|
|
|
@ -2,7 +2,9 @@ require 'spec_helper'
|
|||
|
||||
|
||||
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 @@ describe SauceTV::API do
|
|||
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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue