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

Allow to specify the host for a mock service #186

Closed
ThomasKoppensteiner opened this issue Feb 19, 2019 · 3 comments
Closed

Allow to specify the host for a mock service #186

ThomasKoppensteiner opened this issue Feb 19, 2019 · 3 comments

Comments

@ThomasKoppensteiner
Copy link

ThomasKoppensteiner commented Feb 19, 2019

Currently only the port can be specified for a MockService. The host is hard coded to localhost.

def register_mock_service
unless standalone
url = "http://localhost#{port.nil? ? '' : ":#{port}"}"
ret = Pact::MockService::AppManager.instance.register_mock_service_for(provider_name, url, mock_service_options)
raise "pact-mock_service(v#{Pact::MockService::VERSION}) does not support 'find available port' feature" unless ret
@port = ret
end
end

The AppManager itself also doesn't allow to specify URIs other than http://localhost.

def register_mock_service_for(name, url, options = {})
   uri = URI(url)
   raise "Currently only http is supported" unless uri.scheme == 'http'
   raise "Currently only services on localhost are supported" unless uri.host == 'localhost'
   uri.port = nil if options[:find_available_port]

   app = Pact::MockService.new(
     name: name,
     log_file: create_log_file(name),
     pact_dir: pact_dir,
     pact_specification_version: options.fetch(:pact_specification_version)
   )
   register(app, uri.port)
end

Is there a good reason for that restriction? Our CI environment provides dependencies (other services) on other hosts than localhost.
Are there any plans to changes this?

bethesque added a commit to pact-foundation/pact-mock_service that referenced this issue Feb 21, 2019
@bethesque
Copy link
Member

Is there a good reason for that restriction?

Time.

I've done it now, but I have to be honest, I haven't tested it on anything other than 127.0.0.1 and 0.0.0.0 (time again). Please try it and let me know how you go.

@bheemreddy181-zz
Copy link

Can some one help me understand how to provide the host name here ? In the pact_helper.rb ?

@bethesque
Copy link
Member

themichaelyan pushed a commit to animoto/pact-ruby that referenced this issue Feb 4, 2022
* feat: update http client code

* feat: unlock rack-test dependency to allow version 1.1.0

* chore(release): version 1.38.0

* feat: allow host of mock service to be specified

closes: pact-foundation#186

* chore(release): version 1.39.0

* feat: add support for bearer token

* feat: remove ruby 2.2 tests

* chore(release): version 1.40.0

* docs(readme): add host to example

* feat: redact Authorization header from HTTP client debug output

* chore(release): version 1.41.0

* fix: use to_json instead of JSON.dump because it generates different JSON when used in conjuction with other libraries (eg. Oj)

* chore(release): version 1.41.1

* chore: add metadata links to gemspec (pact-foundation#195)

* chore: revert accidentally commited gemfiles

* fix: file upload spec

* chore: remove jruby support add 2.5 and 2.6

* fix(pact_helper_locator): add 'test' dir to file patterns (pact-foundation#196)

* chore(release): version 1.41.2

* feat: use new 'pacts for verification' endpoint to retrieve pacts (pact-foundation#199)

* chore(release): version 1.42.0

* chore: ensure X_PACT_DEVELOPMENT is unset when running appraisal update

* fix: can't use safe navigation operator because of Ruby 2.2 in Travelling Ruby for the pact-ruby-standalone

* chore(release): version 1.42.1

* fix: remove missed &.

* chore(release): version 1.42.2

* chore: build on Ruby 2.2 because it's required for Travelling Ruby for the pact-ruby-standalone. Drop 2.4 and 2.5, and just do 2.6, as the inbetween versions should be fine

* chore: remove randexp dependency (pact-foundation#202)

* style: code style fixes as per fasterer suggestion (pact-foundation#203)

* Use symbol to proc for slight performance gain
* Replace `reverse.each` with `reverse_each`
* Switch to `tr` for slight performance gain
* Clean up duplicate requires
* Empty lines vacuum

* fix(verify): exit with status 0 if all pacts are in pending state

* chore(release): version 1.42.3

* chore: update gemspec (pact-foundation#204)

* Drop unnecessary encoding pragma
* Use short form __dir__
* Add changelog
* Drop unnecessary `json` requirement
* Require `pry-byebug` for development

* feat(verify): allow includePendingStatus to be specified when fetching pacts

* chore(release): version 1.43.0

* fix: use URI.open instead of Kernel.open

* chore: add ruby 2.7 to testing matrix

* fix: use configured credentials when fetching the diff with previous version

Closes: pact-foundation#205

* chore(deps): update for example

* chore(release): version 1.43.1

* feat(message pact): add DSL for configuring Message Pact verifications

* chore: fix release script so it doesn't release twice

* style: whitespace

* chore: see if I can get deploy happening once only after tests

* chore: put message pact in folder that is not gitignored

* Revert "chore: see if I can get deploy happening once only after tests"

This reverts commit 1750dc3.

* chore(deps): update pact-mock_service to 3.3.1

* chore(release): version 1.44.0

* chore: try the stages again

* fix: print notices from 'pacts for verification' response to indicate why pacts are included an/or pending

* chore(release): version 1.44.1

* fix: show pending test output in yellow instead of red

* feat: support pending pacts in json formatter

* style: whitespace

* feat: use custom json formatter when --format json is specified and send it straight to stdout or the configured file

* chore: ensure logging messages don't screw up the JSON parsing in the test

* chore(release): version 1.45.0

* chore: remove tests for RSpec 2. It's time.

* chore: lock down gems, stop installing pry-byebug on Travis

* chore: rename group because it stopped the gemfiles development dependencies being installed

* chore: remove pry-byebug version restriction

* chore: remove webrick version restriction

* chore: add webrick version restriction back

* fix: remove accidentally committed verbose: true

* feat: expose full notice object in JSON output

* chore: remove gemfiles dir from release script

* chore(release): version 1.46.0

* fix: send output messages to the correct stream when using the XML formatter

* chore(release): version 1.46.1

* chore: echo link to travis build when releasing

[ci-skip]

* feat: add pact metadata to json formatter

* feat: update json formatter output

* chore(release): version 1.47.0

* feat: use certificates from SSL_CERT_FILE and SSL_CERT_DIR environment variables in HTTP connections

* chore(release): version 1.48.0

* feat: use environment variables PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD when verifying a pact by URL, if the environment variables are present

* chore(release): version 1.49.0

* Revert "Fix link to Ron Holshausen's blog post" (pact-foundation#194)

* fix: ensure the presence of basic auth credentials does not cause an error when displaying the path of a pact on the local filesystem

* fix: ensure diff is included in the json output

* chore(release): version 1.49.1

* fix: json parser error for top level JSON values

fixes: pact-foundation/pact-net#237

* chore(release): version 1.49.2

* fix: pact selection verification options logging

* chore(release): version 1.49.3

* docs(contributing): Fix typo

* feat: Set expected interactions on mock service but without writing them to pact file (pact-foundation#210)

* chore(release): version 1.50.0

* fix: fix integration with pact-message-ruby (pact-foundation#216)

* chore(release): version 1.50.1

* feat: allow individual interactions to be re-run by setting PACT_BROKER_INTERACTION_ID

* chore(release): version 1.51.0

* fix: bump rake dependency per CVE-2020-8130 (pact-foundation#219)

* Revert "fix: bump rake dependency per CVE-2020-8130 (pact-foundation#219)" (pact-foundation#220)

This reverts commit 09feaa6.

* fix: update thor dependency (pact-foundation#218)

Co-authored-by: Lindsey Hattamer <[email protected]>

Co-authored-by: Lindsey Hattamer <[email protected]>

* chore: add github release workflow

* chore(deps): update rake to ~> 13.0

* chore: disable travis release

* chore(release): version 1.51.1

* feat: support webdav http methods

* chore(release): version 1.52.0

* feat: add support for the enable_pending flag

* chore(release): version 1.53.0

* feat: add support for include_wip_pacts_since

* feat: allow include_wip_pacts_since to use a Date, DateTime or Time

* feat: use pb relation in preference to beta relation when fetching pacts for verification

* chore(deps): update

* chore(release): version 1.54.0

* chore(deps): update for example

* feat: update output during verification so the pact info shows before the describe blocks of the pact that is being verified

* feat: split pending and failed rerun commands into separate sections

* feat: allow verification task to set just a pact_helper without a URI

* feat: add consumer_version_selectors to pact verification DSL, and convert consumer_version_tags to selectors

* chore(release): version 1.55.0

* fix: remove accidentally committed debug logging

* chore(release): version 1.55.1

* test: remove puts

* chore: update error output when tagging

* fix: correctly calculate exit code when a mix of pending and non pending pacts are verified

Closes: pact-foundation#223

* chore: support old --ignore-failures as well as new pending

* test: update with pact_source

* chore(release): version 1.55.2

* fix: de-duplicate re-run commands

* fix: correct logic for determining if all interactions for a pact have been verified

Closes: pact-foundation#221

* chore: bump pact-message version

* chore(release): version 1.55.3

* fix: add back missing output describing the interactions filter

* chore(release): version 1.55.4

* fix(security): hide personal access token given in uri (pact-foundation#225)

something like https://pat@my-pact-server/pact.json is possible where pat stands for personal access token and is a secret.
fix the current behavior where only https://user:password@my-pact-server/pact.json is checked

* chore(release): version 1.55.5

* Fixed typo with misspell (pact-foundation#226)

* chore: update release workflow [ci-skip]

* fix: require rspec now that pact-support does not depend on it

* chore(release): version 1.55.6

* fix: add consumer name to the selection description (pact-foundation#229)

* fix(pact_selection_description): support consumer name selection

When consumer_version_selection specifies consumer name, the name is
added to the description too.

* fix(pact_selection_description) remove unused variable

* chore(release): version 1.55.7

* feat: catch and log error during help text generation

* chore: update spec to include active support tests

* chore: add test workflow

* chore: remove .travis.yml and update badge

* chore(release): version 1.56.0

* chore: update trigger script [ci-skip]

* feat: allow verbose flag to be set when publishing verifications

* chore: update trigger release script [ci-skip]

* chore(release): version 1.57.0

* fix: gracefully handle display of username that causes InvalidComponentError to be raised when composing a URI

For: pact-foundation/pact-net#289

* chore: don't make ruby 3.0 experimental any more

* feat: support publishing verification results with a version branch

* chore(release): version 1.58.0

* feat: update descriptions for new consumer version selectors

* chore(release): version 1.59.0

* chore: updating pact-support version (pact-foundation#247)

* feat: allow SSL verification to be disabled in the HAL client by setting the environment variable PACT_DISABLE_SSL_VERIFICATION=true

* chore: use output stream not error stream

* chore: update verbose output

* chore: add workflow_dispatch to release workflow

* chore(release): version 1.60.0

* chore: fix grammar

* doc: fixed incorrect use of vowels (pact-foundation#250)

* feat: support description of matching_branch and matching_tag consumer version selectors

* fix: pass through includePendingStatus to the 'pacts for verification' API when it is false

* chore(release): version 1.61.0

Co-authored-by: Beth Skurrie <[email protected]>
Co-authored-by: Victoria Plows <[email protected]>
Co-authored-by: Beth Skurrie <[email protected]>
Co-authored-by: Grey Baker <[email protected]>
Co-authored-by: thatguysimon <[email protected]>
Co-authored-by: Tan Le <[email protected]>
Co-authored-by: mcclenney <[email protected]>
Co-authored-by: Christoph Grabo <[email protected]>
Co-authored-by: Will Djingga <[email protected]>
Co-authored-by: Matt Fellows <[email protected]>
Co-authored-by: thatguysimon <[email protected]>
Co-authored-by: Max Forasteiro <[email protected]>
Co-authored-by: Michael R. Fleet <[email protected]>
Co-authored-by: Lindsey Hattamer <[email protected]>
Co-authored-by: thomas-girotto <[email protected]>
Co-authored-by: Hiroshi SHIBATA <[email protected]>
Co-authored-by: Mateusz Derks <[email protected]>
Co-authored-by: naresh-hopin <[email protected]>
Co-authored-by: Akhil Gautam <[email protected]>
themichaelyan pushed a commit to animoto/pact-mock_service that referenced this issue Feb 4, 2022
* feat: allow mock service host to be configured

pact-foundation/pact-ruby#186

* chore(release): version 3.0.0

* fix: add missing host argument to server spawn

fixes: pact-foundation#102

* chore(release): version 3.0.1

* Improve logging robustness

Do not pretty print a JSON object when serialization or serialization fail, for details see pact-foundation#103.

* Update interaction_replay.rb

* Initial version of the unit test

* Move the test to appropriate context

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* Update interaction_replay.rb

* Update interaction_replay_spec.rb

* Update interaction_replay_spec.rb

* feat: pact-stub-service log level cli opt

* chore(release): version 3.1.0

* chore(release): version 3.1.1

* feat(skip writing to pact): Use writable_interactions when writing to pact file

* Add test for #as_json

* Add feature spec

* Bump pact-support dependency

* Fix tests

* chore(release): version 3.2.0

* CI: Add 2.7 to travis ci

* fix: remove apparently unused require for thwait

* chore(release): version 3.2.1

* feat: log a warning when too many interactions are set on the mock service at once

* chore(release): version 3.3.0

* fix: put metadata on the correct decorator

* chore(release): version 3.3.1

* chore: remove jruby until somebody shows they're actually using it

* chore(release): version 3.4.0

* feat: add token, username and password options to stub service (pact-foundation#118)

Co-authored-by: Beth Skurrie <[email protected]>

* chore(release): version 3.5.0

* docs: document that you can set the broker token via an env var

[ci-skip]

* chore: separate test and deploy stages

* chore: update .travis.yml

[ci-skip]

* chore: update .travis.yml

* test: add expectations to make sure metadata: nil isn't stored in the pact (pact-foundation#119)

* feat: add 'Access-Control-Allow-Headers' = true to cors response headers (pact-foundation#121)

* chore(release): version 3.6.0

* fix:  fix Ruby 2.7 kwargs warning (pact-foundation#122)

* chore(release): version 3.6.1

* fix: update thor dependency (pact-foundation#124)

Co-authored-by: Lindsey Hattamer <[email protected]>

Co-authored-by: Lindsey Hattamer <[email protected]>

* chore: add github workflow for gem release

* chore: disable tests as they're not running properly on github workflow

* chore(release): version 3.6.2

* feat: do not require files until command is executing

* chore: update release workflow [ci-skip]

* feat: use Pact::Query.parse_string to parse query string

* chore(deps): update rake

* docs: update travis badge

* chore(release): version 3.7.0

* feat: include interaction diffs in verification response

cc: @TimothyJones

* chore: add tests to github actions

* chore: allow workflow dispatch to release

* chore(release): version 3.8.0

* chore: tests are hanging. try a subset

* chore: try rspec

* chore: disabling tests, they hang

* chore: create issue template

* feat: pass host into WEBrick options to allow configuration (pact-foundation#128)

Co-authored-by: Matthew Hall <[email protected]>

* chore(release): version 3.9.0

* chore: handle http 2

* fix: check for nil body rather than falsey body when determining how to render mocked response
Fixes: pact-foundation#99

* chore(release): version 3.9.1

Co-authored-by: Beth Skurrie <[email protected]>
Co-authored-by: Alexander Bolshakov <[email protected]>
Co-authored-by: YOU54F <[email protected]>
Co-authored-by: Beth Skurrie <[email protected]>
Co-authored-by: Simon Nizov <[email protected]>
Co-authored-by: Chavez <[email protected]>
Co-authored-by: Chavez <[email protected]>
Co-authored-by: Matt Fellows <[email protected]>
Co-authored-by: vandemark <[email protected]>
Co-authored-by: Bartek Bułat <[email protected]>
Co-authored-by: Michael R. Fleet <[email protected]>
Co-authored-by: Lindsey Hattamer <[email protected]>
Co-authored-by: mhall58 <[email protected]>
Co-authored-by: Matthew Hall <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants