-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some additional tests for identity/identity_alias
- Loading branch information
Showing
4 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "test_helper" | ||
|
||
class IdentityAliasTest < ActiveSupport::TestCase | ||
setup do | ||
@client = Clients::Vault | ||
@identity = Identity.new | ||
email = SecureRandom.hex(4) | ||
@identity.sub = email | ||
@alias_name = @identity.sub | ||
@group_name = SecureRandom.hex(4) | ||
@policies = %w[ my_policy1 my_policy2 ] | ||
@auth_path = "oidc" | ||
end | ||
|
||
test "#put_entity_alias creates an entity_alias" do | ||
assert_raise { @client.read_entity_alias(@identity.sub, @alias_name, @auth_path) } | ||
@client.put_entity(@identity.sub, @policies) | ||
|
||
assert_kind_of Vault::Secret, @client.put_entity_alias(@identity.sub, @alias_name, @auth_path) | ||
entity_alias = @client.read_entity_alias(@identity.sub, @alias_name, @auth_path) | ||
assert_not_nil entity_alias | ||
end | ||
|
||
test "#put_entity_alias skips an existing entity_alias" do | ||
existing_alias = SecureRandom.hex | ||
assert_raise { @client.read_entity_alias(@identity.sub, existing_alias, @auth_path) } | ||
@client.put_entity(@identity.sub, @policies) | ||
assert_kind_of Vault::Secret, @client.put_entity_alias(@identity.sub, existing_alias, @auth_path) | ||
entity_alias = @client.read_entity_alias(@identity.sub, existing_alias, @auth_path) | ||
assert_not_nil entity_alias | ||
|
||
# returns nil/no error when an existing alias exists | ||
assert_nil @client.put_entity_alias(@identity.sub, existing_alias, @auth_path) | ||
entity_alias = @client.read_entity_alias(@identity.sub, existing_alias, @auth_path) | ||
assert_not_nil entity_alias | ||
end | ||
|
||
test "#delete_entity_alias removes an entity_alias" do | ||
@client.put_entity(@identity.sub, @policies) | ||
|
||
assert_kind_of Vault::Secret, @client.put_entity_alias(@identity.sub, @alias_name, @auth_path) | ||
entity_alias = @client.read_entity_alias(@identity.sub, @alias_name, @auth_path) | ||
assert_not_nil entity_alias | ||
|
||
@client.delete_entity_alias(@identity.sub, @alias_name, @auth_path) | ||
assert_raise { @client.read_entity_alias(@identity.sub, @alias_name, @auth_path) } | ||
end | ||
|
||
test "#put_group_alias creates a group_alias" do | ||
assert_raise { @client.read_group_alias(@group_name, @alias_name, @auth_path) } | ||
@client.put_group(@group_name, @policies) | ||
|
||
assert_kind_of Vault::Secret, @client.put_group_alias(@group_name, @alias_name, @auth_path) | ||
group_alias = @client.read_group_alias(@group_name, @alias_name, @auth_path) | ||
assert_not_nil group_alias | ||
end | ||
|
||
test "#put_group_alias skips an existing group_alias" do | ||
existing_alias = SecureRandom.hex | ||
assert_raise { @client.read_group_alias(@group_name, existing_alias, @auth_path) } | ||
@client.put_group(@group_name, @policies) | ||
assert_kind_of Vault::Secret, @client.put_group_alias(@group_name, existing_alias, @auth_path) | ||
group_alias = @client.read_group_alias(@group_name, existing_alias, @auth_path) | ||
assert_not_nil group_alias | ||
|
||
# returns nil/no error when an existing alias exists | ||
assert_nil @client.put_group_alias(@group_name, existing_alias, @auth_path) | ||
group_alias = @client.read_group_alias(@group_name, existing_alias, @auth_path) | ||
assert_not_nil group_alias | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require "test_helper" | ||
|
||
class IdentityTest < ActiveSupport::TestCase | ||
setup do | ||
@client = Clients::Vault | ||
@identity = Identity.new | ||
email = SecureRandom.hex(4) | ||
@identity.sub = email | ||
@group_name = SecureRandom.hex(4) | ||
@policies = %w[ my_policy1 my_policy2 ] | ||
end | ||
|
||
test "#put_entity creates an entity" do | ||
entity = @client.read_entity(@identity.sub) | ||
assert_nil entity | ||
|
||
@client.put_entity(@identity.sub, @policies) | ||
entity = @client.read_entity(@identity.sub) | ||
assert_equal @policies, entity.data[:policies] | ||
end | ||
|
||
test "#put_entity merges policies for an existing entity" do | ||
existing_policies = %w[ policy_from_elsewhere ] | ||
existing_entity = SecureRandom.hex(4) | ||
|
||
@client.put_entity(existing_entity, existing_policies) | ||
policies, metadata = @client.get_entity_data(existing_entity) | ||
assert_equal existing_policies, policies | ||
|
||
@client.put_entity(existing_entity, @policies) | ||
policies, metadata = @client.get_entity_data(existing_entity) | ||
assert_equal @policies + existing_policies, policies | ||
end | ||
|
||
test "#delete_entity removes an entity" do | ||
@client.put_entity(@identity.sub, @policies) | ||
@client.delete_entity(@identity.sub) | ||
entity = @client.read_entity(@identity.sub) | ||
assert_nil entity | ||
end | ||
|
||
test "#put_group creates an group" do | ||
policies, metadata = @client.get_group_data(@group_name) | ||
assert_empty policies | ||
|
||
@client.put_group(@group_name, @policies) | ||
policies, metadata = @client.get_group_data(@group_name) | ||
assert_equal @policies, policies | ||
end | ||
|
||
test "#put_group merges policies for an existing group" do | ||
existing_policies = %w[ policy_from_elsewhere ] | ||
existing_group = SecureRandom.hex(4) | ||
|
||
@client.put_group(existing_group, existing_policies) | ||
policies, metadata = @client.get_group_data(existing_group) | ||
assert_equal existing_policies, policies | ||
|
||
@client.put_group(existing_group, @policies) | ||
policies, metadata = @client.get_group_data(existing_group) | ||
assert_equal @policies + existing_policies, policies | ||
end | ||
end |