test/yao/test_auth.rb in yao-0.2.7 vs test/yao/test_auth.rb in yao-0.2.8
- old
+ new
@@ -1,109 +1,18 @@
class TestAuth < Test::Unit::TestCase
+ include AuthStub
- AUTH_JSON = \
- "{\"auth\":{\"passwordCredentials\":{\"username\":\"udzura\",\"password\":\"XXXXXXXX\"},\"tenantName\":\"example\"}}"
-
- RESPONSE_JSON = <<-JSON
-{
- "access": {
- "token": {
- "issued_at": "2015-08-31T03:58:36.073232",
- "expires": "2015-09-01T03:58:36Z",
- "id": "aaaa166533fd49f3b11b1cdce2430000",
- "tenant": {
- "description": "Testing",
- "enabled": true,
- "id": "aaaa166533fd49f3b11b1cdce2430000",
- "name": "example"
- }
- },
- "serviceCatalog": [
- {
- "endpoints": [
- {
- "adminURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
- "region": "RegionOne",
- "internalURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44",
- "id": "1a66e6af97c440b2a7bbc4f9735923d9",
- "publicURL": "http://nova-endpoint.example.com:8774/v2/b598bf98671c47e1b955f8c9660e3c44"
- }
- ],
- "endpoints_links": [],
- "type": "compute",
- "name": "nova"
- },
- {
- "endpoints": [
- {
- "adminURL": "http://neutron-endpoint.example.com:9696/",
- "region": "RegionOne",
- "internalURL": "http://neutron-endpoint.example.com:9696/",
- "id": "0418104da877468ca65d739142fa3454",
- "publicURL": "http://neutron-endpoint.example.com:9696/"
- }
- ],
- "endpoints_links": [],
- "type": "network",
- "name": "neutron"
- },
- {
- "endpoints": [
- {
- "adminURL": "http://glance-endpoint.example.com:9292",
- "region": "RegionOne",
- "internalURL": "http://glance-endpoint.example.com:9292",
- "id": "246f33509ff64802b86eb081307ecec0",
- "publicURL": "http://glance-endpoint.example.com:9292"
- }
- ],
- "endpoints_links": [],
- "type": "image",
- "name": "glance"
- },
- {
- "endpoints": [
- {
- "adminURL": "http://endpoint.example.com:12345/v2.0",
- "region": "RegionOne",
- "internalURL": "http://endpoint.example.com:5000/v2.0",
- "id": "2b982236cc084128bf42b647c1b7fb49",
- "publicURL": "http://endpoint.example.com:5000/v2.0"
- }
- ],
- "endpoints_links": [],
- "type": "identity",
- "name": "keystone"
- }
- ],
- "user": {
- "username": "udzura",
- "roles_links": [],
- "id": "a9994b2dee82423da7da572397d3157a",
- "roles": [
- {
- "name": "admin"
- }
- ],
- "name": "udzura"
- },
- "metadata": {
- "is_admin": 0,
- "roles": [
- "ce5330c512cc4bd289b3a725ad1106b7"
- ]
- }
- }
-}
- JSON
-
def setup
- stub_request(:post, "http://endpoint.example.com:12345/v2.0/tokens").with(body: AUTH_JSON)
- .to_return(:status => 200, :body => RESPONSE_JSON, :headers => {'Content-Type' => 'application/json'})
+ @auth_url = "http://endpoint.example.com:12345"
+ username = "udzura"
+ tenant = "example"
+ password = "XXXXXXXX"
- Yao.config.set :auth_url, "http://endpoint.example.com:12345"
- @token = Yao::Auth.new(tenant_name: "example", username: "udzura", password: "XXXXXXXX")
+ stub_auth_request(@auth_url, username, password, tenant)
+
+ Yao.config.set :auth_url, @auth_url
+ @token = Yao::Auth.new(tenant_name: tenant, username: username, password: password)
end
def teardown
end
@@ -130,11 +39,10 @@
assert { cli.url_prefix.to_s == "http://neutron-endpoint.example.com:9696/v2.0" }
end
def test_token_is_valid
assert { @token.token == "aaaa166533fd49f3b11b1cdce2430000" }
- assert { @token.issued_at == Time.parse("2015-08-31T03:58:36.073232") }
- assert { @token.expire_at == Time.parse("2015-09-01T03:58:36Z") }
+ assert { @token.expire_at - @token.issued_at == 3600 }
assert { @token.endpoints.size == 4 }
end
def test_hooked_by_configure_block
auth = Yao::Auth