Sha256: e9e5041d3430f55a33a45afef327556bd71aca1ab7a75909f8f1194a96117732

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 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
      })

    assert { t.expired? }

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

  def test_reflesh
    auth_url = "http://endpoint.example.com:12345"
    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
      })
    assert { t.token == "old_token" }

    stub_auth_request(auth_url, username, password, tenant)

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yao-0.2.11 test/yao/test_token.rb
yao-0.2.10 test/yao/test_token.rb
yao-0.2.9 test/yao/test_token.rb
yao-0.2.8 test/yao/test_token.rb