Skip to content

Commit

Permalink
Fix flakey test and deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
suprjinx committed Sep 30, 2024
1 parent e2a3410 commit 7a73bdc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gem "bootsnap", require: false

# High-level app logic
gem "interactor", "~> 3.0"
gem "ostruct"

# Use the vault-ruby gem to interact with HashiCorp Vault
gem "vault"
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
ostruct (0.6.0)
parallel (1.26.2)
parser (3.3.4.2)
ast (~> 2.4.1)
Expand Down Expand Up @@ -290,6 +291,7 @@ DEPENDENCIES
interactor (~> 3.0)
jbuilder
jwt
ostruct
puma (>= 5.0)
rails (~> 7.2.1)
rubocop-rails-omakase
Expand Down
6 changes: 3 additions & 3 deletions app/lib/clients/vault/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def configure_root_ca
root_cert = client.logical.write("#{root_ca_mount}/root/generate/internal",
common_name: "astral.internal",
issuer_name: root_ca_ref,
ttl: "87600h").data
ttl: "87600h").data[:certificate]
# save the root certificate
File.write("tmp/#{root_ca_mount}.crt", root_cert)

Expand Down Expand Up @@ -92,13 +92,13 @@ def sign_cert
issuer_ref: root_ca_ref,
csr: intermediate_csr,
format: "pem_bundle",
ttl: "43800h").data
ttl: "43800h").data[:certificate]

# save the signed intermediate certificate
File.write("tmp/#{intermediate_ca_mount}.cert.pem", intermediate_cert)

# set the signed intermediate certificate
client.logical.write("#{intermediate_ca_mount}/intermediate/set-signed", certificate: intermediate_cert[:certificate])
client.logical.write("#{intermediate_ca_mount}/intermediate/set-signed", certificate: intermediate_cert)
end

def configure_ca
Expand Down
13 changes: 8 additions & 5 deletions test/integration/secrets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@ class SecretsTest < ActionDispatch::IntegrationTest
end

test "#show" do
create_secret
path = create_secret
# view the secret
get secret_path("top/secret/key"), headers: { "Authorization" => "Bearer #{jwt_authorized}" }
get secret_path(path), headers: { "Authorization" => "Bearer #{jwt_authorized}" }
assert_response :success
%w[ data metadata lease_id ].each do |key|
assert_includes response.parsed_body["secret"].keys, key
end
end

test "#delete" do
create_secret
path = create_secret
# delete the secret
delete destroy_secret_path("top/secret/key"), headers: { "Authorization" => "Bearer #{jwt_authorized}" }
delete destroy_secret_path(path), headers: { "Authorization" => "Bearer #{jwt_authorized}" }
assert_response :success
end

private

def create_secret
# make a path
path = "top/secret/#{SecureRandom.hex}"
# create the secret
post secrets_path, headers: { "Authorization" => "Bearer #{jwt_authorized}" },
params: { secret: { path: "top/secret/key", data: { password: "sicr3t" } } }
params: { secret: { path: path, data: { password: "sicr3t" } } }
path
end

def remove_pki_engine
Expand Down

0 comments on commit 7a73bdc

Please sign in to comment.