Sha256: f902ee95b008df003a3e1165f79734b13893312953c81b89cb05ea768acd10d3

Contents?: true

Size: 1.66 KB

Versions: 64

Compression:

Stored size: 1.66 KB

Contents

require 'helper'
require 'uuidtools'

class HIDTest < Vault::TestCase

  # HID.hid? is true(ish) when given HIDs and false(ish) when not
  def test_hid?
    assert_equal(:user, Vault::HID.hid?('user1@heroku.com'))
    assert_equal(:app, Vault::HID.hid?('app123@heroku.com'))
    refute Vault::HID.hid?('employee@heroku.com')
  end

  # HID.hid_to_uuid converts an app ID to a v5 UUID based on a URL scheme.
  def test_app_id_to_uuid
    url = "https://vault.heroku.com/apps/1234"
    uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
    assert_equal(uuid, Vault::HID.hid_to_uuid('app1234@heroku.com'))
  end

  # HID.hid_to_uuid converts a Heroku app ID to a v5 UUID based on a URL
  # scheme.
  def test_user_id_to_uuid
    url = "https://vault.heroku.com/users/1234"
    uuid = UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, url).to_s
    assert_equal(uuid, Vault::HID.hid_to_uuid('user1234@heroku.com'))
  end

  # HID.hid_to_uuid raises a ArgumentError if the specified ID doesn't match
  # the expected format.
  def test_hid_to_uuid_with_invalid_heroku_id
    error = assert_raises(ArgumentError) do
      Vault::HID.hid_to_uuid('invalid1234@heroku.com')
    end
    assert_equal('invalid1234@heroku.com is not a valid Heroku app or user ID.',
                 error.message)
  end

  # HID.hid_to_uuid raises a ArgumentError if the specified ID doesn't match
  # the expected format.
  def test_hid_to_uuid_with_subtly_invalid_heroku_id
    error = assert_raises(ArgumentError) do
      Vault::HID.hid_to_uuid('app1234--afasd-afas')
    end
    assert_equal('app1234--afasd-afas is not a valid Heroku app ID.',
                 error.message)
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
vault-tools-2.1.1 test/hid_test.rb
vault-tools-2.1.0 test/hid_test.rb
vault-tools-2.0.2 test/hid_test.rb
vault-tools-2.0.1 test/hid_test.rb
vault-tools-2.0.0 test/hid_test.rb
vault-tools-1.0.1 test/hid_test.rb
vault-tools-1.0.0 test/hid_test.rb
vault-tools-0.7.1 test/hid_test.rb
vault-tools-0.7.0 test/hid_test.rb
vault-tools-0.6.5 test/hid_test.rb
vault-tools-0.6.4 test/hid_test.rb
vault-tools-0.6.3 test/hid_test.rb
vault-tools-0.6.2 test/hid_test.rb
vault-tools-0.6.1 test/hid_test.rb
vault-tools-0.6.0 test/hid_test.rb
vault-tools-0.5.22 test/hid_test.rb
vault-tools-0.5.21 test/hid_test.rb
vault-tools-0.5.19 test/hid_test.rb
vault-tools-0.5.18 test/hid_test.rb
vault-tools-0.5.17 test/hid_test.rb