Skip to content

Commit

Permalink
refactor: move 422 message text into en.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 3, 2020
1 parent db9f7f4 commit 5ec0009
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/pact_broker/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ en:
non_templated_host?: "cannot have a template parameter in the host"
pacticipant_exists?: "does not match an existing pacticipant"


pact_broker:
messages:
response_body_hidden: For security purposes, the response details are not logged. To enable response logging, configure the webhook_host_whitelist property. See %{base_url}/doc/webhooks#whitelist for more information.
Expand Down Expand Up @@ -53,6 +54,9 @@ en:
$ curl -v -XPOST -H "Content-Type: application/json" -d "{\"name\": \"%{new_name}\"}" %{create_pacticipant_url}
If the pact broker requires basic authentication, add '-u <username:password>' to the command.
To disable this check, set `check_for_potential_duplicate_pacticipant_names` to false in the configuration.
new_line_in_url_path: URL path cannot contain a new line character.
tab_in_url_path: URL path cannot contain a tab character.

"400":
title: 400 Malformed Request
message: The request was malformed and could not be processed.
Expand Down
8 changes: 6 additions & 2 deletions lib/rack/pact_broker/invalid_uri_protection.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# frozen_string_literal: true

require 'uri'
require 'pact_broker/messages'


# This class is for https://github.com/pact-foundation/pact_broker/issues/101
# curl -i "http://127.0.0.1:9292/<script>"

module Rack
module PactBroker
class InvalidUriProtection
include ::PactBroker::Messages

def initialize app
@app = app
end
Expand Down Expand Up @@ -43,9 +47,9 @@ def parse uri
def validate(uri)
decoded_path = URI.decode(uri.path)
if decoded_path.include?("\n")
'URL path cannot contain a new line character.'
message('errors.new_line_in_url_path')
elsif decoded_path.include?("\t")
'URL path cannot contain a tab character.'
message('errors.tab_in_url_path')
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/rack/pact_broker/invalid_uri_protection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module PactBroker

it "returns a 422" do
expect(subject.status).to eq 422
expect(subject.body).to include "new line"
end
end

Expand All @@ -40,6 +41,7 @@ module PactBroker

it "returns a 422" do
expect(subject.status).to eq 422
expect(subject.body).to include "tab"
end
end
end
Expand Down

0 comments on commit 5ec0009

Please sign in to comment.