Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX URI path handling to remove double slashes #344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/vault/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ def request(verb, path, data = {}, headers = {})
end
end

# Removes double slashes from a path.
#
# @param [String]
#
# @return [String]
def remove_double_slash(path)
path.b.gsub(%r{//+}, '/')
end

# Construct a URL from the given verb and path. If the request is a GET or
# DELETE request, the params are assumed to be query params are are
# converted as such using {Client#to_query_string}.
Expand Down Expand Up @@ -333,6 +342,8 @@ def build_uri(verb, path, params = {})
# Don't merge absolute URLs
uri = URI.parse(File.join(address, path)) unless uri.absolute?

uri.path = remove_double_slash(uri.path)

# Return the URI object
uri
end
Expand Down
41 changes: 41 additions & 0 deletions spec/integration/api/logical_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ module Vault
expect(secret).to be
expect(secret.data).to eq(foo: "bar")
end

it "allows double slash" do
subject.write("secret/test-read", foo: "bar")
secret = subject.read("secret///test-read")
expect(secret).to be
expect(secret.data).to eq(foo: "bar")
end

it "allows double slash and special characters" do
subject.write("secret/b:@c%n-read-slash", foo: "bar")
secret = subject.read("secret///b:@c%n-read-slash")
expect(secret).to be
expect(secret.data).to eq(foo: "bar")
end
end

describe "#write" do
Expand All @@ -84,6 +98,21 @@ module Vault
expect(secret.data).to eq(bacon: true)
end

it "allows double slash" do
subject.write("secret///test-write", zip: "zap")
result = subject.read("secret/test-write")
expect(result).to be
expect(result.data).to eq(zip: "zap")
end

it "allows double slash and special characters" do
subject.write("secret///b:@c%n-write", foo: "bar")
subject.write("secret///b:@c%n-write", bacon: true)
secret = subject.read("secret/b:@c%n-write")
expect(secret).to be
expect(secret.data).to eq(bacon: true)
end

it "respects spaces properly" do
key = 'secret/sub/"Test Group"'
subject.write(key, foo: "bar")
Expand All @@ -107,6 +136,18 @@ module Vault
expect(subject.read("secret/b:@c%n-delete")).to be(nil)
end

it "allows double slash" do
subject.write("secret/delete", foo: "bar")
expect(subject.delete("secret///delete")).to be(true)
expect(subject.read("secret/delete")).to be(nil)
end

it "allows double slash and special characters" do
subject.write("secret/b:@c%n-delete-slash", foo: "bar")
expect(subject.delete("secret///b:@c%n-delete-slash")).to be(true)
expect(subject.read("secret/b:@c%n-delete-slash")).to be(nil)
end

it "does not error if the secret does not exist" do
expect {
subject.delete("secret/delete")
Expand Down
Loading