Sha256: 34966497576483c7ff62166f71f34cb1b48d3bf0fd79fa53a9aafddc9f2ff7f1

Contents?: true

Size: 1.97 KB

Versions: 39

Compression:

Stored size: 1.97 KB

Contents

class TestToken < Test::Unit::TestCase
  include AuthStub

  def setup
    stub(Yao.config).debug { false }
    stub(Yao.config).debug_record_response { false }
  end

  def test_expired
    t = Yao::Token.new({})
    t.register({
        "id" => "aaaa166533fd49f3b11b1cdce2430000",
        "issued_at" => Time.now.iso8601,
        "expires" => (Time.now - 3600).utc.iso8601,
        "tenant" => {
          "id" => "aaaa166533fd49f3b11b1cdce2430000"
        }
      })

    assert { t.expired? }

    t.register({
        "id" => "aaaa166533fd49f3b11b1cdce2430000",
        "issued_at" => Time.now.iso8601,
        "expires" => (Time.now + 3600).utc.iso8601,
        "tenant" => {
          "id" => "aaaa166533fd49f3b11b1cdce2430000"
        }
      })
    assert { ! t.expired? }
  end

  def test_refresh
    auth_url = "http://endpoint.example.com:12345/v2.0"
    username = "udzura"
    tenant   = "example"
    password = "XXXXXXXX"

    auth_info = {
      auth: {
        passwordCredentials: {
          username: username, password: password
        },
        tenantName: tenant
      }
    }
    t = Yao::Token.new(auth_info)
    t.register({
        "id" => "old_token",
        "issued_at" => Time.now.iso8601,
        "expires" => (Time.now - 3600).utc.iso8601,
        "tenant" => {
          "id" => "aaaa166533fd49f3b11b1cdce2430000"
        }
      })
    assert { t.token == "old_token" }

    stub_auth_request(auth_url, username, password, tenant)

    Yao.config.auth_url auth_url
    t.refresh(Yao.default_client.default)

    assert { t.token == "aaaa166533fd49f3b11b1cdce2430000" }
  end

  def test_current_tenant_id
    t = Yao::Token.new({})
    t.register({
        "id" => "aaaa166533fd49f3b11b1cdce2430000",
        "issued_at" => Time.now.iso8601,
        "expires" => (Time.now - 3600).utc.iso8601,
        "tenant" => {
          "id" => "aaaa166533fd49f3b11b1cdce2430000"
        }
      })

    assert { Yao.current_tenant_id == "aaaa166533fd49f3b11b1cdce2430000" }
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
yao-0.9.1 test/yao/test_token.rb
yao-0.9.0 test/yao/test_token.rb
yao-0.8.0 test/yao/test_token.rb
yao-0.7.0 test/yao/test_token.rb
yao-0.6.3 test/yao/test_token.rb
yao-0.6.2 test/yao/test_token.rb
yao-0.6.1 test/yao/test_token.rb
yao-0.6.0 test/yao/test_token.rb
yao-0.5.0 test/yao/test_token.rb
yao-0.4.3 test/yao/test_token.rb
yao-0.4.2 test/yao/test_token.rb
yao-0.4.1 test/yao/test_token.rb
yao-0.4.0 test/yao/test_token.rb
yao-0.3.8 test/yao/test_token.rb
yao-0.3.7 test/yao/test_token.rb
yao-0.3.6 test/yao/test_token.rb
yao-0.3.5 test/yao/test_token.rb
yao-0.3.4 test/yao/test_token.rb
yao-0.3.3 test/yao/test_token.rb