|
3 | 3 | require 'spec_helper'
|
4 | 4 | require_relative '../../../lib/vmfloaty/auth'
|
5 | 5 |
|
| 6 | +user = 'first.last' |
| 7 | +pass = 'password' |
| 8 | + |
6 | 9 | describe Pooler do
|
| 10 | + |
7 | 11 | before :each do
|
8 | 12 | @abs_url = 'https://abs.example.com/api/v2'
|
9 | 13 | end
|
|
15 | 19 | end
|
16 | 20 |
|
17 | 21 | it 'returns a token from abs' do
|
18 |
| - stub_request(:post, 'https://first.last:[email protected]/api/v2/token') |
| 22 | + stub_request(:post, 'https://abs.example.com/api/v2/token') |
| 23 | + .with(headers: get_headers(username: user, password: pass, content_length: 0)) |
19 | 24 | .to_return(status: 200, body: @get_token_response, headers: {})
|
20 | 25 |
|
21 |
| - token = Auth.get_token(false, @abs_url, 'first.last', 'password') |
| 26 | + token = Auth.get_token(false, @abs_url, user, pass) |
22 | 27 | expect(token).to eq @token
|
23 | 28 | end
|
24 | 29 |
|
25 | 30 | it 'raises a token error if something goes wrong' do
|
26 |
| - stub_request(:post, 'https://first.last:[email protected]/api/v2/token') |
| 31 | + stub_request(:post, 'https://abs.example.com/api/v2/token') |
| 32 | + .with(headers: get_headers(username: user, password: pass, content_length: 0)) |
27 | 33 | .to_return(status: 500, body: '{"ok":false}', headers: {})
|
28 | 34 |
|
29 |
| - expect { Auth.get_token(false, @abs_url, 'first.last', 'password') }.to raise_error(TokenError) |
| 35 | + expect { Auth.get_token(false, @abs_url, user, pass) }.to raise_error(TokenError) |
30 | 36 | end
|
31 | 37 | end
|
32 | 38 |
|
|
37 | 43 | end
|
38 | 44 |
|
39 | 45 | it 'deletes the specified token' do
|
40 |
| - stub_request(:delete, 'https://first.last:[email protected]/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y') |
| 46 | + stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y') |
| 47 | + .with(headers: get_headers(username: user, password: pass)) |
41 | 48 | .to_return(status: 200, body: @delete_token_response, headers: {})
|
42 | 49 |
|
43 |
| - expect(Auth.delete_token(false, @abs_url, 'first.last', 'password', |
44 |
| - @token)).to eq JSON.parse(@delete_token_response) |
| 50 | + expect(Auth.delete_token(false, @abs_url, user, pass, |
| 51 | + @token)).to eq JSON.parse(@delete_token_response) |
45 | 52 | end
|
46 | 53 |
|
47 | 54 | it 'raises a token error if something goes wrong' do
|
48 |
| - stub_request(:delete, 'https://first.last:[email protected]/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y') |
| 55 | + stub_request(:delete, 'https://abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y') |
| 56 | + .with(headers: get_headers(username: user, password: pass)) |
49 | 57 | .to_return(status: 500, body: '{"ok":false}', headers: {})
|
50 | 58 |
|
51 |
| - expect { Auth.delete_token(false, @abs_url, 'first.last', 'password', @token) }.to raise_error(TokenError) |
| 59 | + expect { Auth.delete_token(false, @abs_url, user, pass, @token) }.to raise_error(TokenError) |
52 | 60 | end
|
53 | 61 |
|
54 | 62 | it 'raises a token error if no token provided' do
|
55 |
| - expect { Auth.delete_token(false, @abs_url, 'first.last', 'password', nil) }.to raise_error(TokenError) |
| 63 | + expect { Auth.delete_token(false, @abs_url, user, pass, nil) }.to raise_error(TokenError) |
56 | 64 | end
|
57 | 65 | end
|
58 | 66 |
|
|
64 | 72 |
|
65 | 73 | it 'checks the status of a token' do
|
66 | 74 | stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
67 |
| - .with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' }) |
| 75 | + .with(headers: get_headers) |
68 | 76 | .to_return(status: 200, body: @token_status_response, headers: {})
|
69 | 77 |
|
70 | 78 | expect(Auth.token_status(false, @abs_url, @token)).to eq JSON.parse(@token_status_response)
|
71 | 79 | end
|
72 | 80 |
|
73 | 81 | it 'raises a token error if something goes wrong' do
|
74 | 82 | stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
75 |
| - .with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' }) |
| 83 | + .with(headers: get_headers) |
76 | 84 | .to_return(status: 500, body: '{"ok":false}', headers: {})
|
77 | 85 |
|
78 | 86 | expect { Auth.token_status(false, @abs_url, @token) }.to raise_error(TokenError)
|
|
0 commit comments