* feat: update the paths in the spec files * feat: update hardcoded paths with path helpers * chore: update hardcoded paths to path helpers * chore: hardcode describe blocks * chore: oops * feat: update some more hardcoded to use link_to's * fix broken tests * chore: admin_articles path * chore: oops remove rails helper * feat: add starting / * chore: more pre slashes * chore: add pre slashes * chore: some small typos * fix: oops
64 lines
2 KiB
Ruby
64 lines
2 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "/admin/advanced/secrets", type: :request do
|
|
before do
|
|
allow(AppSecrets).to receive(:vault_enabled?).and_return(true)
|
|
allow(AppSecrets).to receive(:[]=)
|
|
end
|
|
|
|
context "when the user is not an admin" do
|
|
it "blocks the request" do
|
|
user = create(:user)
|
|
sign_in user
|
|
|
|
expect do
|
|
get admin_secrets_path
|
|
end.to raise_error(Pundit::NotAuthorizedError)
|
|
end
|
|
end
|
|
|
|
context "when the user is an admin" do
|
|
let(:admin) { create(:user, :admin) }
|
|
|
|
before { sign_in admin }
|
|
|
|
describe "GET /admin/advanced/secrets" do
|
|
it "renders with status 200" do
|
|
get admin_secrets_path
|
|
expect(response.status).to eq 200
|
|
end
|
|
|
|
it "displays an alert when Vault is not enabled" do
|
|
allow(AppSecrets).to receive(:vault_enabled?).and_return(false)
|
|
get admin_secrets_path
|
|
expect(response.body).to include("Vault is not currently setup for your application")
|
|
end
|
|
end
|
|
|
|
describe "PUT /admin/advanced/secrets" do
|
|
let(:valid_secret) { AppSecrets::SETTABLE_SECRETS.first }
|
|
let(:valid_params) { { valid_secret => "SECRET_VALUE" } }
|
|
|
|
it "successfully sets a secret and shows flash message" do
|
|
allow(AppSecrets).to receive(:[]=)
|
|
put admin_secrets_path, params: valid_params
|
|
expect(response.status).to eq 302
|
|
expect(AppSecrets).to have_received(:[]=).with(valid_secret, "SECRET_VALUE")
|
|
expect(flash[:success]).to include("Secret #{valid_secret} was successfully updated in Vault")
|
|
end
|
|
|
|
it "returns a bad_request with invalid params" do
|
|
put admin_secrets_path, params: {}
|
|
expect(response.status).to eq 400
|
|
end
|
|
|
|
it "creates an audit log" do
|
|
Audit::Subscribe.listen :internal
|
|
expect do
|
|
put admin_secrets_path, params: valid_params
|
|
end.to change(AuditLog, :count).by(1)
|
|
Audit::Subscribe.forget :internal
|
|
end
|
|
end
|
|
end
|
|
end
|