Skip to content

Commit

Permalink
one more test for group preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Nov 17, 2024
1 parent 7f5823d commit 12b366d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/lib/clients/vault/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def get_entity_data(sub)
get_identity_data("identity/entity/name/#{sub}")
end

def read_group(name)
client.logical.read("identity/group/name/#{name}")
end

def get_group_data(name)
get_identity_data("identity/group/name/#{name}")
end
Expand Down
34 changes: 34 additions & 0 deletions test/lib/clients/vault/identity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,38 @@ class IdentityTest < ActiveSupport::TestCase
policies, metadata = @client.get_group_data(existing_group)
assert_equal @policies + existing_policies, policies
end

test "#put_group retains existing fields (member_entity_ids, type, metadata, etc)" do
existing_policies = %w[ policy_from_elsewhere ]
existing_group = SecureRandom.hex(4)
existing_metadata = { existing_md: "some value" }
entity = @client.put_entity(@identity.sub, @policies)

params = {
policies: existing_policies,
metadata: existing_metadata,
member_entity_ids: [ entity.data[:id] ],
type: "internal"
}
write_identity(
path: "identity/group",
name: existing_group,
params: params
)
group = @client.read_group(existing_group)
assert_equal existing_policies, group.data[:policies]

@client.put_group(existing_group, @policies)
group = @client.read_group(existing_group)
assert_equal existing_metadata, group.data[:metadata]
assert_equal [ entity.data[:id] ], group.data[:member_entity_ids]
assert_equal "internal", group.data[:type]
end

private

def write_identity(path:, name:, params:)
full_path = "#{path}/name/#{name}"
@client.send(:client).logical.write(full_path, params)
end
end

0 comments on commit 12b366d

Please sign in to comment.