Code Monkey home page Code Monkey logo

pact-foundation / pact-js-core Goto Github PK

View Code? Open in Web Editor NEW
148.0 8.0 80.0 23.72 MB

Core binaries for pact-js, a Contract Testing Framework. NOTE: If you are looking to do Pact contract testing in node, you almost certainly want pact-js, not pact-node.

Home Page: https://docs.pact.io

License: MIT License

JavaScript 0.87% TypeScript 60.58% Ruby 0.06% Shell 6.16% Python 1.04% C++ 28.22% C 3.07%
pact pact-node pact-js nodejs hacktoberfest smartbear-supported

pact-js-core's Introduction

ℹ️ Usage notice
This is a core library, designed for use in the bowels of another package. Unless you are wanting to develop tools for the pact ecosystem, you almost certainly want to install @pact-foundation/pact instead

Build and test Known Vulnerabilities GitHub release npm license slack

Npm package license Npm package version Minimum node.js version

Npm package total downloads

Npm package yearly downloads Npm package monthly downloads Npm package daily downloads

Npm package dependents

Maintenance

Build and test Publish and release

Linux macOS Windows

Pact-JS Core

A wrapper for the Pact CLI Tools.

Installation

npm install @pact-foundation/pact-core --save-dev

Do Not Track

In order to get better statistics as to who is using Pact, we have an anonymous tracking event that triggers when Pact installs for the first time. To respect your privacy, anyone can turn it off by simply adding a 'do not track' flag within their package.json file:

{
 "name": "some-project",
 ...
 "config": {
  "pact_do_not_track": true
 },
 ...
}

Which Library/Package should I use?

TL;DR - you almost always want Pact JS.

Purpose Library Comments
Synchronous / HTTP APIs Pact JS
Asynchronous APIs Pact JS
Node.js Pact JS
Browser testing Pact Web You probably still want Pact JS. See Using Pact in non-Node environments *
Isomorphic testing Pact Web You probably still want Pact JS. See Using Pact in non-Node environments *
Publishing to Pact Broker Pact Node Included in Pact JS distribution

* The "I need to run it in the browser" question comes up occasionally. The question is this - for your JS code to be able to make a call to another API, is this dependent on browser-specific code? In most cases, people use tools like React/Angular which have libraries that work on the server and client side, in which case, these tests don't need to run in a browser and could instead be executed in a Node.js environment.

Usage

Simply require the library and call the create function to start the mock service

var pact = require("@pact-foundation/pact-core");
var server = pact.createServer({ port: 9999 });
server.start().then(function() {
 // Do your testing/development here
});

Or if you're using Typescript instead of plain old Javascript

import pact from "@pact-foundation/pact-core";
const server = pact.createServer({ port: 9999 });
server.start().then(() => {
 // Do your testing/development here
});

Or you can also use the CLI

$# pact mock --port 9999

To see the list commands possible with the CLI, simply ask for help $# pact --help

Documentation

Set Log Level

var pact = require("@pact-foundation/pact-core");
pact.logLevel("debug");

or you can set it via an environment variable

LOG_LEVEL=debug

Mock Servers

Mock servers are used by Pact to record interactions and create pact contracts.

Create Mock Server

var pact = require('@pact-foundation/pact-core');
var server = pact.createServer({
 ...
});

Options:

Parameter Required? Type Description
port false number Port number that the server runs on, defaults to random available port
host false string Host on which to bind the server on, defaults to 'localhost'. Supports '0.0.0.0' to bind on all IPv4 addresses on the local machine.
log false string File to log output on relative to current working directory, defaults to none
logLevel false LogLevel (string) Log level to pass to the pact core. One of "DEBUG", "ERROR", "WARN", "INFO", can be set by LOG_LEVEL env var
ssl false boolean Create a self-signed SSL cert to run the server over HTTPS , defaults to false
sslcert false string Path to a custom self-signed SSL cert file, 'ssl' option must be set to true to use this option, defaults to none
sslkey false string Path a custom key and self-signed SSL cert key file, 'ssl' option must be set to true to use this, defaults to none
cors false boolean Allow CORS OPTION requests to be accepted, defaults to 'false'
dir false string Directory to write the pact contracts relative to the current working directory, defaults to none
spec false number The pact specification version to use when writing pact contracts, defaults to '1'
consumer false string The name of the consumer to be written to the pact contracts, defaults to none
provider false string The name of the provider to be written to the pact contracts, defaults to none
pactFileWriteMode false overwrite OR update OR merge Control how the pact file is created. Defaults to "overwrite"
format false json OR xml Format to write the results as, either in JSON or XML, defaults to JSON
out false string Write output to a file instead of returning it in the promise, defaults to none
timeout false number How long to wait for the mock server to start up (in milliseconds). Defaults to 30000 (30 seconds)

List Mock Servers

If you ever need to see which servers are currently created.

var pact = require("@pact-foundation/pact-core");
var servers = pact.listServers();
console.log(JSON.stringify(servers));

Remove All Mock Servers

Remove all servers once you're done with them in one fell swoop.

var pact = require("@pact-foundation/pact-core");
pact.removeAllServers();

Start a Mock Server

Start the current server.

var pact = require("@pact-foundation/pact-core");
pact.createServer()
 .start()
 .then(function() {
  // Do something after it started
 });

Stop a Mock server

Stop the current server.

var pact = require("@pact-foundation/pact-core");
pact.createServer()
 .stop()
 .then(function() {
  // Do something after it stopped
 });

Delete a Mock server

Stop the current server and deletes it from the list.

var pact = require("@pact-foundation/pact-core");
pact.createServer()
 .delete()
 .then(function() {
  // Do something after it was killed
 });

Check if a Mock server is running

var pact = require("@pact-foundation/pact-core");
pact.createServer().running;

Mock Server Events

There's 3 different events available, 'start', 'stop' and 'delete'. They can be listened to the same way as an EventEmitter.

var pact = require("@pact-foundation/pact-core");
var server = pact.createServer();
server.on("start", function() {
 console.log("started");
});
server.on("stop", function() {
 console.log("stopped");
});
server.on("delete", function() {
 console.log("deleted");
});

Provider Verification

Read more about Verify Pacts.

var pact = require('@pact-foundation/pact-core');

pact.verifyPacts({
 ...
});

Options:

Parameter Required? Type Description
providerBaseUrl true string Running API provider host endpoint.
pactBrokerUrl false string Base URL of the Pact Broker from which to retrieve the pacts. Required if pactUrls not given.
provider false string Name of the provider if fetching from a Broker
consumerVersionSelectors false ConsumerVersionSelector|array Use Selectors to is a way we specify which pacticipants and versions we want to use when configuring verifications.
consumerVersionTags false string|array Retrieve the latest pacts with given tag(s)
providerVersionTags false string|array Tag(s) to apply to the provider application
includeWipPactsSince false string Includes pact marked as WIP since this date. String in the format %Y-%m-%d or %Y-%m-%dT%H:%M:%S.000%:z
pactUrls false array Array of local pact file paths or HTTP-based URLs. Required if not using a Pact Broker.
providerStatesSetupUrl false string URL to send PUT requests to setup a given provider state
pactBrokerUsername false string Username for Pact Broker basic authentication
pactBrokerPassword false string Password for Pact Broker basic authentication
pactBrokerToken false string Bearer token for Pact Broker authentication
publishVerificationResult false boolean Publish verification result to Broker (NOTE: you should only enable this during CI builds)
providerVersion false string Provider version, required to publish verification result to Broker. Optional otherwise.
enablePending false boolean Enable the pending pacts feature.
timeout false number The duration in ms we should wait to confirm verification process was successful. Defaults to 30000.
logLevel false LogLevel (string) Log level. One of "TRACE", "DEBUG", "ERROR", "WARN", "INFO", can be set by LOG_LEVEL env var

The consumer version selector looks like this:

ConsumerVersionSelector {
  tag?: string;
  latest?: boolean;
  consumer?: string;
  deployedOrReleased?: boolean;
  deployed?: boolean; 
  released?: boolean; 
  environment?: string;
  fallbackTag?: string;
  branch?: string;
  mainBranch?: boolean;
  matchingBranch?: boolean;
}

See the Pact Broker documentation on selectors for more information.

Pact Broker Publishing

var pact = require('@pact-foundation/pact-core');
var opts = {
 ...
};

pact.publishPacts(opts).then(function () {
 // do something
});

Options:

Parameter Required? Type Description
pactFilesOrDirs true array Array of local Pact files or directories containing them. Required.
pactBroker true string URL of the Pact Broker to publish pacts to. Required.
consumerVersion true string A string containing a semver-style version e.g. 1.0.0. Required.
pactBrokerUsername false string Username for Pact Broker basic authentication. Optional
pactBrokerPassword false string Password for Pact Broker basic authentication. Optional
pactBrokerToken false string Bearer token for Pact Broker authentication. Optional
tags false array An array of Strings to tag the Pacts being published. Optional
branch false string The branch to associate with the published pacts. Optional but recommended
autoDetectVersionProperties false boolean Automatically detect the repository branch from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps. Optional
buildUrl false string The build URL that created the pact. Optional
verbose false boolean Enables verbose output for underlying pact binary.

Pact Broker Deployment Check

var pact = require('@pact-foundation/pact-core');
var opts = {
 ...
};

pact.canDeploy(opts)
 .then(function (result) {
  // You can deploy this
    // If output is not specified or is json, result describes the result of the check.
    // If outout is 'table', it is the human readable string returned by the check
 })
 .catch(function(error) {
  // You can't deploy this
    // if output is not specified, or is json, error will be an object describing
    // the result of the check (if the check failed),
    // if output is 'table', then the error will be a string describing the output from the binary,

    // In both cases, `error` will be an Error object if something went wrong during the check.
 });

Options:

Parameter Required? Type Description
pacticipants true []objects An array of version selectors in the form `{ name: String, latest?: string
specify a tag, use the tagname with latest. Specify one of these per pacticipant
that you want to deploy
pactBroker true string URL of the Pact Broker to query about deployment. Required.
pactBrokerUsername false string Username for Pact Broker basic authentication. Optional
pactBrokerPassword false string Password for Pact Broker basic authentication. Optional
pactBrokerToken false string Bearer token for Pact Broker authentication. Optional
output false json,table Specify output to show, json or table. Optional, Defaults to json.
verbose false boolean Enables verbose output for underlying pact binary.
retryWhileUnknown false number The number of times to retry while there is an unknown verification result. Optional
retryInterval false number The time between retries in seconds, use with retryWhileUnknown. Optional
to false string The tag that you want to deploy to (eg, 'prod')

Stub Servers

Stub servers create runnable APIs from existing pact files.

The interface is comparable to the Mock Server API.

Create Stub Server

var pact = require('@pact-foundation/pact-core');
var server = pact.createStub({
 ...
});

Options:

Parameter Required? Type Description
pactUrls true array List of local Pact files to create the stub service from
port false number Port number that the server runs on, defaults to random available port
host false string Host on which to bind the server on, defaults to 'localhost'. Supports '0.0.0.0' to bind on all IPv4 addresses on the local machine.
log false string File to log output on relative to current working directory, defaults to none
logLevel false LogLevel (string) Log level to pass to the pact core. One of "DEBUG", "ERROR", "WARN", "INFO", can be set by LOG_LEVEL env var
ssl false boolean Create a self-signed SSL cert to run the server over HTTPS , defaults to 'false'
sslcert false string Path to a custom self-signed SSL cert file, 'ssl' option must be set to true to use this option. Defaults false
sslkey false string Path a custom key and self-signed SSL cert key file, 'ssl' option must be set to true to use this option false. Defaults to none
cors false boolean Allow CORS OPTION requests to be accepted, defaults to 'false'
timeout false number How long to wait for the stub server to start up (in milliseconds). Defaults to 30000 (30 seconds)

Message Pacts

Create Message Pacts

var pact = require('@pact-foundation/pact-core');
var message = pact.createMessage({
 ...
});

Options:

Parameter Required? Type Description
dir true string Directory to write the pact contracts relative to the current working directory, defaults to none
consumer true string The name of the consumer to be written to the pact contracts, defaults to none
provider true string The name of the provider to be written to the pact contracts, defaults to none
pactFileWriteMode false `"overwrite" "update"
Example
const messageFactory = messageFactory({
 consumer: "consumer",
 provider: "provider",
 dir: dirname(`${__filename}/pacts`),
 content: `{
  "description": "a test mesage",
  "content": {
   "name": "Mary"
  }
 }`
});

messageFactory.createMessage();

CLI Tools

This package also comes with the Pact Standalone Tools available as linked binaries in the standard NPM installation directory (e..g. ./node_modules/.bin).

This means you may call them direct from scripts in your package json, for example:

"scripts": {
  "pactPublish": "pact-broker publish ./pacts --consumer-app-version=$\(git describe\) --broker-base-url=$BROKER_BASE_URL --broker-username=$BROKER_USERNAME --broker-password=BROKER_PASSWORD"`
}
These are available in circumstances where `pact-core` has not yet implemented a feature or access via JavaScript APIs is not desirable. To run the binaries is as simple as the following:

*Example can-i-deploy check*:
```sh
./node_modules/.bin/pact-broker can-i-deploy --pacticipant "Banana Service" --broker-base-url https://test.pact.dius.com.au --latest --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1

Computer says no ¯\_(ツ)_/¯

CONSUMER       | C.VERSION | PROVIDER       | P.VERSION | SUCCESS?
---------------|-----------|----------------|-----------|---------
Banana Service | 1.0.0     | Fofana Service | 1.0.0     | false

The verification between the latest version of Banana Service (1.0.0) and version 1.0.0 of Fofana Service failed

The following are the binaries currently made available:

  • pact-mock-service
  • pact-broker
  • pact-stub-service
  • pact-message
  • pact-provider-verifier
  • pact

Windows Issues

Enable Long Paths

Windows has a default path length limit of 260 causing issues with projects that are nested deep inside several directory and with how npm handles node_modules directory structures. To fix this issue, please enable Windows Long Paths in the registry by running regedit.exe, find the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled and change the value from 0 to 1, then reboot your computer. Pact should now work as it should, if not, please raise an issue on github.

Contributing

To develop this project, simply install the dependencies with npm install --ignore-scripts, and run npm run watch to for continual development, linting and testing when a source file changes.

Testing

Running npm test will execute the tests that has the *.spec.js pattern.

Questions?

Please search for potential answers or post question on our official Pact StackOverflow.

pact-js-core's People

Contributors

adamwitko avatar bangn avatar bethesque avatar danymarques avatar davids-pup avatar dependabot[bot] avatar flagoon avatar github-actions[bot] avatar grahamhar avatar inksprout avatar kuangp avatar mboudreau avatar mefellows avatar millerick avatar mmoll avatar neezer avatar oxlade39 avatar pact-dev avatar rashiagarwal avatar snyk-bot avatar tarciosaraiva avatar tijwelch avatar timothyjones avatar timvahlbrock avatar tonynguyenit18 avatar trp-dan-oxlade avatar vgrigoruk avatar vwong avatar you54f avatar zsims avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pact-js-core's Issues

Pact-node's ruby bindings don't work if the project name has spaces

Software versions

  • OS: macOS 10.13.3, Centos 7 (probably)
  • Consumer Pact library: 5.9.1
  • Node Version: 8

Expected behaviour

It shouldn't matter whether the directory name has or hasn't spaces on its name.

Actual behaviour

When creating the mock server, it somehow split the project path where spaces exist: /var/lib/jenkins/workspace/My Cool App/, and attempts to run Cool as a command. It then, of course, fails saying

/node_modules/@pact-foundation/pact-node/standalone/darwin-1.43.1/lib/ruby/bin/ruby: line 14: Cool: command not found

Steps to reproduce

  1. Change the name of your app to something with spaces (if possible with 3 words), like: my-cool-app to My Cool App.
  2. Run the PactJS tests.

npm install @pact-foundation/pact-node fails: Cannot find module 'rimraf'

Installation of pact-node fails since version 6.12.0 if rimraf has not been previously installed.

Tested with Node versions:

  • 4.8.7
  • 6.13.0
  • 8.9.4

On macOS High Sierra

Steps to reproduce:
Execute @pact-foundation/[email protected] on a clean node environment (i.e. no node modules installed)

$ npm install @pact-foundation/[email protected]

....


gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  ACTION binding_gyp_ndtp_target_build_ndtp .
  TOUCH Release/obj.target/ndtp.stamp

> [email protected] postinstall /Users/********/node_modules/spawn-sync
> node postinstall


> [email protected] postinstall /Users/********/node_modules/caporal
> (test -f ./node_modules/husky/bin/install.js && node ./node_modules/husky/bin/install.js) || exit 0


> @pact-foundation/[email protected] postinstall /Users/********/node_modules/@pact-foundation/pact-node
> node postinstall.js

module.js:540
    throw err;
    ^

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  ACTION binding_gyp_ndtp_target_build_ndtp .
  TOUCH Release/obj.target/ndtp.stamp

> [email protected] postinstall /Users/********/node_modules/spawn-sync
> node postinstall


> [email protected] postinstall /Users/stello/git/contract-testing-cli/node_modules/caporal
> (test -f ./node_modules/husky/bin/install.js && node ./node_modules/husky/bin/install.js) || exit 0


> @pact-foundation/[email protected] postinstall /Users/********/node_modules/@pact-foundation/pact-node
> node postinstall.js

module.js:540
    throw err;
    ^

Error: Cannot find module 'rimraf'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/**********/node_modules/@pact-foundation/pact-node/standalone/install.js:10:14)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @pact-foundation/[email protected] postinstall: `node postinstall.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @pact-foundation/[email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Seems that your installation scripts rely on rimraf which is only declared as a devDependency.

Workaround:

Execute npm install rimraf first.

accept relative paths for pact files

as mentioned in #79, i was surprised to find that the cli did not accept paths that were relative to the project root in npm scripts. while an absolute path does work, a relative path normally works with cli tools as well.

i don't necessarily think its too limiting to only accept absolute paths, but it should at least be made more clear in the documentation that the limitation exists.

this is not a blocker for me, so this issue is just to give visibility to the confusion i ran into.

Typescript declarations not found

When trying to upgrade pact-node in the pact module and removing the custom typings I had results in the following issue (truncated for readability):

src/pact-web.ts(20,28): error TS7016: Could not find a declaration file for module '@pact-foundation/pact-node'. '/Users/mfellows/development/public/pact-js/node_modules/@pact-foundation/pact-node/src/index.js' implicitly has an 'any' type.
  Try `npm install @types/@pact-foundation/pact-node` if it exists or add a new declaration (.d.ts) file containing `declare module '@pact-foundation/pact-node';`

I'm running the latest TypeScript (v2.6.1 at this time). Even though the advice from https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html says:

Also note that if your main declaration file is named index.d.ts and lives at the root of the package (next to index.js) you do not need to mark the "types" property, though it is advisable to do so.

Manually adding "types": "./src/index.d.ts", to package.json solves the issue.

Without this, I must use the non-TS const pact = require('...') declaration, losing the nice auto-completion etc. and benefits of TS.

Feature Request: Create binstubs for pact-standalone binaries

AS a user who wants to integrate to the latest Pact CLI features
IT would be useful to be able to easily reference the Pact binaries (e.g. pact, pact-broker pact-message etc.)
SO that I can use them without having to write JS wrappers, or wait for them to be included in the JS library

Example use case

Prior to deployment, we often run the can-i-deploy tool to check if it's safe to release either a consumer or a provider. Bash is an appropriate tool for this. It's hard to find the CLI tools if you don't know what you're doing, but it is possible:

package.json:

"can-i-deploy:consumer": "$(find ./node_modules -name pact-broker | grep -e 'bin/pact-broker$' | head -n 1) can-i-deploy --pacticipant SNSPactEventConsumer --latest --broker-base-url https://test.pact.dius.com.au --broker-username xxx --broker-password yyy",

Typically, I just install the CLI tools into my Docker container and add them to the path. But it would be nice if I could just go:

package.json:

can-i-deploy:consumer": "pact-broker can-i-deploy --pacticipant SNSPactEventConsumer --latest --broker-base-url https://test.pact.dius.com.au --broker-username xxx --broker-password yy

I imagine the ./node_modules/.bin dir might look like:

ls ./node_modules/.bin
pact_broker -> ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.33.1/bin/pact-broker
pact -> ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.33.1/bin/pact
...

Behind a firewall pact-node fails to install

We have a CI environment behind a firewall, so we fail to install pact-node because it tries to download the server binaries from github.

Is there a way to handle an install behind a firewall? I can think of a couple ways we could get around this. There may be a way to specify a location to download the binaries from (like an on-prem artifactory server or something). Alternatively, we could download the binaries and put them into our codebase and (somehow) tell pact-node where they are on an install.

Can't install latests pact-node

I get the following error when trying to install the latests pact version (5.0.0)

$ npm install --save-dev pact-web @pact-foundation/pact-node
npm ERR! path /path/to/node_modules/@pact-foundation/pact-node/bin/pact-cli.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/path/to/node_modules/@pact-foundation/pact-node/bin/pact-cli.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /path/to/.npm/_logs/2017-10-02T18_53_06_366Z-debug.log

Not finding linux pact mock service on centos 7

I was previously using nodejs 4.3.2 on a centos 7 linux box running jenkins.
Since I've updated to nodejs 8.3.0, I can't seem to be able to require @pact-foundation/pact-node.
I get the following error:

Warning: Cannot find module '@pact-foundation/pact-mock-service-linux-x64'� Use --force to continue.

I tried with @pact-foundation/pact-node version v4.8.1 and v4.12.0 (latest).

I first noticed the problem with karma-pact, but the problem happens in another repo where I don't use karma-pact.

Cannot find module './build/Release/DTraceProviderBindings' from 'dtrace-provider.js'

Running pact in jest I get the error:

Error: Cannot find module './build/Release/DTraceProviderBindings' from 'dtrace-provider.js'
[...]

This seems to be the same problem as the one mentioned in issue 63 for pact-js, which according to @mefellows is an upstream problem with pact-node, therefore I'm raising the issue here.

The node-bunyan issue mentioned in the thread states that the problem has been fixed in [email protected]. As far as I can tell it should therefore be sufficient to upgrade from bunyan version 1.8.2 to 1.8.4 to resolve this problem.

Improve compiler validations to support use as library

As pact-node is a library (in addition to a tool) and will be embedded in potentially many others, we have a duty to ensure the highest levels of TS language use.

An annoying restriction of TS is that it will compile, and therefore complain, about upstream dependencies.

e.g. for pact-js even with exclusions set as follows:

  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "./node_modules/**/*",
    "./dist",
    "./examples",
    "**/*.spec.ts"
  ]

TS still picts up pact-node, as it is in compilation scope, so all compiler options for the external project are applied equally to pact-node, resulting in lots of errors (I disabled the noImplicitAny to reduce noise):

node_modules/@pact-foundation/pact-node/src/broker.ts(70,21): error TS2532: Object is possibly 'undefined'.
node_modules/@pact-foundation/pact-node/src/broker.ts(70,53): error TS2532: Object is possibly 'undefined'.
node_modules/@pact-foundation/pact-node/src/broker.ts(81,17): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
node_modules/@pact-foundation/pact-node/src/logger.ts(11,8): error TS2339: Property 'info' does not exist on type 'Logger'.
node_modules/@pact-foundation/pact-node/src/logger.ts(19,36): error TS2339: Property 'level' does not exist on type 'Logger'.
node_modules/@pact-foundation/pact-node/src/logger.ts(25,16): error TS2554: Expected 0 arguments, but got 1.
node_modules/@pact-foundation/pact-node/src/pact-util.ts(7,9): error TS7030: Not all code paths return a value.
node_modules/@pact-foundation/pact-node/src/publisher.ts(100,20): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
node_modules/@pact-foundation/pact-node/src/server.ts(243,4): error TS2322: Type 'undefined' is not assignable to type 'ChildProcess'.
node_modules/@pact-foundation/pact-node/src/verifier.ts(31,25): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.
node_modules/@pact-foundation/pact-node/src/verifier.ts(112,7): error TS2532: Object is possibly 'undefined'.
src/dsl/verifier.ts(8,25): error TS2339: Property 'verifyPacts' does not exist on type 'typeof "/Users/mfellows/development/public/pact-js/node_modules/@pact-foundation/pact-node/src/in...'.
src/pact.ts(59,34): error TS2339: Property 'createServer' does not exist on type 'typeof "/Users/mfellows/development/public/pact-js/node_modules/@pact-foundation/pact-node/src/in...'.
src/pact.ts(70,20): error TS2339: Property 'logLevel' does not exist on type 'typeof "/Users/mfellows/development/public/pact-js/node_modules/@pact-foundation/pact-node/src/in...'.

My suggestion is that we increase strictness/validation compilation rules, but I'm open to other alternatives.

Connection Refused error when attempting to `createServer`

Since upgrading to 5.2.x I'm getting the following error when trying to run createServer.

[2017-11-07T20:41:59.511Z]  INFO: [email protected]/13140 on localhost:
    Creating Pact Server with options:
    host = 127.0.0.1,
    port = 9993,
    log = /Users/mfellows/development/public/pact-js/logs/mockserver-integration.log,
    dir = /Users/mfellows/development/public/pact-js/pacts,
    spec = 2,
    ssl = false,
    sslcert = ,
    sslkey = ,
    cors = false


  Integration
    Pact on http protocol
      1) "before all" hook
      2) "after all" hook

  0 passing (82ms)
  2 failing

  1) Integration Pact on http protocol "before all" hook:
     Uncaught TypeError: Cannot read property 'message' of null
      at Request._callback (/Users/mfellows/development/public/pact-js/node_modules/@pact-foundation/pact-node/src/server.ts:327:121)
      at Request.self.callback (/Users/mfellows/development/public/pact-js/node_modules/request/request.js:188:22)
      at emitTwo (events.js:125:13)
      at Request.emit (events.js:213:7)
      at Request.<anonymous> (/Users/mfellows/development/public/pact-js/node_modules/request/request.js:1171:10)
      at emitOne (events.js:115:13)
      at Request.emit (events.js:210:7)
      at IncomingMessage.<anonymous> (/Users/mfellows/development/public/pact-js/node_modules/request/request.js:1091:12)
      at Object.onceWrapper (events.js:314:30)
      at emitNone (events.js:110:20)
      at IncomingMessage.emit (events.js:207:7)
      at endReadableNT (_stream_readable.js:1047:12)
      at _combinedTickCallback (internal/process/next_tick.js:102:11)
      at process._tickCallback (internal/process/next_tick.js:161:9)

  2) Integration Pact on http protocol "after all" hook:
     Error: connect ECONNREFUSED 127.0.0.1:9993
      at Object.exports._errnoException (util.js:1016:11)
      at exports._exceptionWithHostPort (util.js:1039:20)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:14)

The issue seemingly can be traced back to the following line related to waiting for the server to start:

http(config, (err, res) => (!err && res.statusCode === 200) ? deferred.resolve() : deferred.reject(`HTTP Error: '${err.message}'`));

In the rejection path, err may be null (in this case it is) and that crashes the entire promise chain, bailing out of any retry logic and recovering when the service is up. Temporarily removing the .message resolves the issue entirely.

I need to do more to dig into this, but creating this as a scratchpad for my findings.

Update to ruby-standalone 1.8.0 and delegate publishPacts to new pact-publish executable

@bethesque commented on Sat Sep 30 2017

The pact-publish command merges pact files for the same consumer/provider (that have been created by running in specs in parallel) before publishing them to the broker.

Usage:
  pact-publish PACT_DIRS_OR_FILES ... -a, --consumer-app-version=CONSUMER_APP_VERSION -b, --broker-base-url=BROKER_BASE_URL

Options:
  -a, --consumer-app-version=CONSUMER_APP_VERSION  # The consumer application version
  -b, --broker-base-url=BROKER_BASE_URL            # The base URL of the Pact Broker
  -n, [--broker-username=BROKER_USERNAME]          # Pact Broker basic auth username
  -p, [--broker-password=BROKER_PASSWORD]          # Pact Broker basic auth password
  -t, [--tag=TAG]                                  # Tag name for consumer version. Can be specified multiple times.
  -v, [--verbose=VERBOSE]                          # Verbose output

Publish pacts to a Pact Broker.

@mefellows commented on Mon Oct 16 2017

cc: @mboudreau I assume this needs to go in pact-node?


@mboudreau commented on Mon Oct 16 2017

@mefellows pact-node/pact-standalone, yep.

having trouble verifying pacts from broker

when running verifyPacts with pactUrls pointing to local files, it is successfully doing verification of the pact. however, as soon as i try to change the url to point to a pact on my remote broker (https and using basic auth), i get the following error:

[Error: /bin/sh: <part of the password>: command not found
/bin/sh: <a different part of the password>: command not found
/Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/app/lib/pact/provider_verifier/app.rb:32:in `get_pact_consumer_name': undefined method `[]' for nil:NilClass (NoMethodError)
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/app/lib/pact/provider_verifier/app.rb:55:in `block in verify_pacts'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/app/lib/pact/provider_verifier/app.rb:54:in `collect'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/app/lib/pact/provider_verifier/app.rb:54:in `verify_pacts'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/app/lib/pact/provider_verifier/cli.rb:18:in `verify'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/vendor/ruby/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/admin/development/travi.org/api/node_modules/@pact-foundation/pact-provider-verifier-darwin/lib/app/pact-provider-verifier.rb:3:in `<main>'
]

note that the pact that i was using locally was a file fetched directly from the same url and credentials using postman.

i would expect that if it were failing to fetch from the broker, that i would get an error related to the fetch, but i'm not sure how to get more information about the context of the error. i did notice that parts of my password for the broker show up in the error (the minor edits in the output above). they seem to be split after & characters. if this is the case, i'm surprised that i don't get a "failed to auth" error before it tries to parse for a consumer name.

could you provide some guidance about how to dig deeper? is there a way to put the ruby portion into a debug mode? if this issue is that special characters need to be escaped, i'm not sure what the sequence would need to be here since i am passing the string as an option to verifyPacts. could it be updated to do the necessary escaping automatically?

Metadata object in pact file not standards compliant

IN #34 we found a problem where the metadata section of the pact generated by my pact-js consumer tests is not compatible with the pact-jvm's PactReader.loadPact resolves the pact spec version.

This code in PactReader (from the master branch/latest version):

 static Pact loadPact(Map options = [:], def source) {
    def pact = loadFile(source, options)
    def version = '2.0.0'
    def specification = pact.metadata?.'pact-specification'
    if (specification instanceof Map && specification.version) {
      version = specification.version
    }
    if (version == '3.0') {
        version = '3.0.0'
    }
    def specVersion = Version.valueOf(version)
    switch (specVersion.majorVersion) {
        case 3:
            return loadV3Pact(source, pact)
        default:
            return loadV2Pact(source, pact)
    }
  }

expects a metadata spec. version section that has this format:


"metadata": {
        "pact-specification": {
            "version": "x.x.x"
        }

BUT pacts generated from pact-js generates a metadata section that looks like this:


"metadata": {
    "pactSpecificationVersion": "3.0.0"
  }

See #34 and https://github.com/realestate-com-au/pact/issues/137 for background.

Strange issue reading contract file

For some reason any time pact node attempts to retrieve a contract file (via http or file system) there is an error reading the contract.

Error: reading pact at /path/to/json.json

What I know is:

  • I've tried multiple contract files on the file system/http requests to no success.
  • Doing a manual GET request to the HTTP URLs I'm using works fine.
  • Permissions of the contract files on the file system are fine.
  • Happens in both 4.7.0 and 4.8.0 and really only just started happening without any change to my environment.
  • The contracts themselves are valid JSON and look correct as far as structure.
  • Looks like the same issue if you skip pact-node and go straight to the verifier.

Not much to go on, but have you seen this before?

Could I use this in gulp?

I was thinking of trying to use this as part of a build tool like grunt, but am having trouble figuring out how to programmatically run the pact broker via your wrapper. Could you offer any guidance?

Thank you!

Shouldn't need to URL encode name of provider in verification settings

@bethesque commented on Mon Aug 07 2017

In the documentation for the js workshop, the provider name needed to be URL encoded. I think this should be handled by the publish code, not by the user.

https://github.com/DiUS/pact-workshop-js/#step-13---using-a-pact-broker

let opts = {
  provider: 'Our%20Provider',
  providerBaseUrl: 'http://localhost:8081',
  providerStatesUrl: 'http://localhost:8081/states',
  providerStatesSetupUrl: 'http://localhost:8081/setup',
  pactBrokerUrl: 'https://test.pact.dius.com.au/',
  tags: ['prod'],
  pactBrokerUsername: 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M',
  pactBrokerPassword: 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1',
  publishVerificationResult: true,
  providerVersion: '1.1.0'
}

@mefellows commented on Sat Aug 19 2017

Agree, that's a bit shit of us.

Encoding Error when publishing pacts

We currently face an encoding problem while publishing pacts to the pact broker from our npm build on a gitlab CI runner.

The same script works fine from our local windows machines and has worked fine on gitlab (unix), too, until we introduced the "€" symbol into the pacts.

This is the stacktrace:

    Could not publish pact:
    /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /builds/renew/ui/node_modules in PATH, mode 040777
    
    Error making request - Encoding::InvalidByteSequenceError "\xE2" on US-ASCII /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/pact_file.rb:28:in `pact_hash', attempt 1 of 3
    
    
    Error making request - Encoding::InvalidByteSequenceError "\xE2" on US-ASCII /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/pact_file.rb:28:in `pact_hash', attempt 2 of 3
    
    
    Error making request - Encoding::InvalidByteSequenceError "\xE2" on US-ASCII /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/pact_file.rb:28:in `pact_hash', attempt 3 of 3
    
    
    /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/json-2.1.0/lib/json/common.rb:156:in `encode'
    : 
    "\xE2" on US-ASCII
     (
    Encoding::InvalidByteSequenceError
    )
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/json-2.1.0/lib/json/common.rb:156:in `initialize'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/json-2.1.0/lib/json/common.rb:156:in `new'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/json-2.1.0/lib/json/common.rb:156:in `parse'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/pact_file.rb:28:in `pact_hash'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/pact_file.rb:20:in `consumer_name'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:98:in `consumer_name'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:80:in `rescue in tag_consumer_version'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:73:in `tag_consumer_version'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:68:in `block in apply_tags'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:67:in `each'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:67:in `all?'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:67:in `apply_tags'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:27:in `call'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/publish_pacts.rb:13:in `call'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/cli/broker.rb:125:in `publish_pacts'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/cli/broker.rb:51:in `publish'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.0/lib/pact_broker/client/cli/custom_thor.rb:15:in `start'
    
    	from /builds/renew/ui/node_modules/@pact-foundation/pact-standalone/platforms/linux-x64/lib/app/pact-broker.rb:28:in `<main>'

Any ideas how we can address this issue?

Verifier doesnt support HTTPS broker URLs

When running pact.verifyPacts() the pactUrls array doesn't seem to support HTTPS broker URLs.

Looking at pact-provider-verifier-darwin/lib/app/lib/pact/provider_verifier/app.rb:88 it appears to parse the URL and then re-construct it with a HTTP scheme.

'caporal' dependency not found at runtime when running the cli

When installing pact via yarn add --dev @pact-foundation/pact-node, trying to run the cli from ./node_modules/.bin produces the following error:

./node_modules/.bin/pact stub
module.js:557
    throw err;
    ^

Error: Cannot find module 'caporal'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/yusef/work/code/yusef/s4l-catalog-api-client/node_modules/@pact-foundation/pact-node/bin/pact-cli.js:5:11)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

This seems to be because the caporal module is listed in devDependencies in package.json. Since it's required at runtime, it seems like this should be moved to the dependencies section.

Inconsistency in tagging pacts while publishing to broker

We are trying to tag pact files, but the only first found pact file is tagged.
import pact from '@pact-foundation/pact-node';

const opts = {
pactFilesOrDirs: [${__dirname}/../../../pacts/*/],
pactBroker: brokerurl,
pactBrokerUsername: brokerusername,
pactBrokerPassword: brokerpassword,
consumerVersion: '1.0.0',
tags : ['prod', 'test']
};

pact.publishPacts(opts)
.then(() => {})
.catch(e => {
console.error('Pact contract publishing failed: ', e);
process.exit(1);
});
Any idea how to solve this issue?

Verifier doesn't return error information to client

Currently we only log Verifier output (using Bunyan), it would be preferable to have the output returned in the promise chain so that we can properly handle it in downstream libs (pact-js, mocha etc.). The current message 'Pact Verification failed' is insufficient information, and too late to make a programmatic call to output logs.

When things succeed, this data is generally not required and is noise, but when things fail we need to be able to programatically access that information.

I suggest we pipe the stderr/out to a variable and return it in the promise rejection (and success) at https://github.com/pact-foundation/pact-node/blob/master/src/verifier.js#L104.

Do not fail installation when Google Analytics call fails

I had trouble installing pact. I kept getting the following error:

> @pact-foundation/[email protected] postinstall /Users/bao/.nvm/versions/node/v8.9.1/lib/node_modules/@pact-foundation/pact-node
> node postinstall.js

Installing Pact Standalone Binary for darwin.
Downloading Pact Standalone Binary v1.43.0 for platform darwin from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.43.0/pact-1.43.0-osx.tar.gz
Please note: we are tracking this download anonymously to gather important usage statistics. To disable tracking, set 'DO_NOT_TRACK=true' as an environment variable.
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 0.0.0.0:443
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)

Only when I set DO_NOT_TRACK=true the installation worked. I believe that the call to Google Analytics failed.

Please add a catch clause to that call so it does not break the installation if the call fails.

Update error message for local files

When adding local json files with the provider option pactFilesOrDirs, I receive an error:

Error: Must provide the pactFilesOrDirs argument if no brokerUrl provided

Shouldn't the error message look like:

Error: Must provide the pactUrls argument if no brokerUrl provided

Proposal: use user-configured self-signed certs in Mock Service health check

Found https://github.com/pact-foundation/pact-node/blob/866d73eb92ca64346163389f9ac72d7e3827aec6/src/server.ts#L262-L266 as part of #58. I assume it's been around a while, so it wasn't appropriate to add as part of that review.

I'm not sure setting this without a users' explicit permission is ever a good idea.

If people are running self-signed certificates they should either a) provide them (in the form of sslkey and sslcert) to us or b) explicitly allow an insecure connection.

My thinking here is that we should use the options.sslkey and options.sslcert in this call, or add an --insecure flag/option for this purpose.

Please add --monkeypatch option to pact mock service start up command and pact-provider-verifier command

@bethesque commented on Tue Nov 07 2017

Requires standalone version pact-1.19.0.

This is to support: pact-foundation/pact-mock_service#78 and another issue that I can't currently find.

The feature that the user is requesting is not something that should be changed for all users, as it is a non-standard behaviour, and breaks the Rack spec. However, we can allow the underlying code to be monkey patched for his specific use case. The value supplied to --monkeypatch will be an absolute path to a ruby file that will monkeypatch the underlying header logic.

This is not something that we need to document, but we can use it to deal with edge cases when necessary!


@mefellows commented on Tue Nov 07 2017

Moving this to pact-node as that is where the the CLI is integrated.

Publisher issues

I pulled the code to try and submit a fix but the tests keep failing - even on a clean clone - so I decided to write an issue here.

Issue 1

Under publisher.js on line 99 it uses urlJoin to create a URL to PUT to pact-broker. The issue here is related to data.provider and data.consumer which are both objects. You have to retrieve the actual name by using data.provider.name and data.consumer.name otherwise the URL built will look like

/pacts/provider/[Object%20object]/consumer/[Object%20object]/version/2.0

Issue 2

When there's a failure there's no way to know what happened. On publisher.js line 114 pass back the response object when the promise is rejected.

Thanks

certificate verify failed

I am running my app locally using self signed cert. When I run the Provider validation. I am getting below error. Is there way to avoid certificate validation ?
failure/Error: replay_interaction interaction
OpenSSL::SSL::SSLError:
SSL_connect returned=1 errno=0 state=error: certificate verify failed

Errors in latest provider-verifier

When running tests with the latest provider-verifier, I'm seeing some errors coming up from the binary, but the tests still pass. Is it cause for concern?

Server Spec
Start server
✓ should dispatch event when starting (1015ms)
(node:17217) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:113:in read': Is a directory @ io_fread - /home/mboudreau/Work/pact/pact-node/node_modules/mocha/bin (Errno::EISDIR) from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:113:in get_json_from_local_file'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:94:in get_json' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:31:in get_pact_consumer_name'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:65:in block in verify_pacts' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:64:in collect'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:64:in verify_pacts' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/cli.rb:21:in verify'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/command.rb:27:in run' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in invoke_command'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor.rb:369:in dispatch' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/base.rb:444:in start'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/pact-provider-verifier.rb:3:in `

'

  ✓ should change running state to true (1021ms)
  when no options are set
    ✓ should start correctly with defaults (1022ms)
  when invalid options are set
    ✓ should fail if custom ssl certs do not exist
    ✓ should fail if custom ssl keys do not exist
    ✓ should fail if custom ssl cert is set, but ssl key isn't
    ✓ should fail if custom ssl key is set, but ssl cert isn't
  when valid options are set
    ✓ should start correctly when instance is delayed (6026ms)
    ✓ should start correctly with ssl (1038ms)
    ✓ should start correctly with custom ssl cert/key (1040ms)
    ✓ should start correctly with custom ssl cert/key but without specifying ssl flag (1050ms)
    ✓ should start correctly with cors (1028ms)
    ✓ should start correctly with port (1040ms)
    ✓ should start correctly with host (1032ms)
    ✓ should start correctly with spec version 1 (1032ms)
    ✓ should start correctly with spec version 2 (1027ms)
    ✓ should start correctly with dir (1036ms)
    ✓ should start correctly with log (1035ms)
    ✓ should start correctly with consumer name (1024ms)
    ✓ should start correctly with provider name (1073ms)
Stop server
  when already started
    ✓ should stop running (1031ms)
    ✓ should dispatch event when stopping (1034ms)
    ✓ should change running state to false (1034ms)
Delete server
  when already running
    ✓ should stop & delete server (1037ms)
    ✓ should dispatch event when deleting (1033ms)
    ✓ should change running state to false (1031ms)

Verifier Spec
Verifier
when automatically finding pacts from a broker
when not given --pact-urls and only --provider
✓ should fail with an error
when not given --pact-urls and only --pact-broker-url
✓ should fail with an error
when given valid arguments
✓ should return a Verifier object
when not given --pact-urls or --provider-base-url
✓ should fail with an error
when given --provider-states-url and not --provider-states-setup-url
✓ should fail with an error
when given --provider-states-setup-url and not --provider-states-url
✓ should fail with an error
when given local Pact URLs that don't exist
✓ should fail with an error
when given an invalid timeout
✓ should fail with an error
when given remote Pact URLs that don't exist
✓ should pass through to the Pact Verifier regardless
when given local Pact URLs that do exist
✓ should not fail
when requested to publish verification results to a Pact Broker
and specifies a provider version
✓ should pass through to the Pact Verifier
when requested to publish verification results to a Pact Broker
and does not specify provider version
✓ should fail with an error
when given the correct arguments
✓ should return a Verifier object
verify
when given a successful scenario
with no provider States
✓ should return a successful promise with exit-code 0

Publish Spec
Pact Broker Mock listening on port: 9221
when publishing a to a broker
without authentication
and the Pact contract is valid
✓ should successfully publish all Pacts (43ms)
✓ should successfully tag all Pacts with 'test' and 'latest'
and the Pact contract is invalid
[2017-05-11T15:41:50.468Z] ERROR: [email protected]/17217 on JAX: Invalid Pact contract given. Unable to parse consumer and provider name
Error: Invalid Pact contract given. Unable to parse consumer and provider name
at constructPutUrl (/home/mboudreau/Work/pact/pact-node/src/publisher.js:193:9)
at /home/mboudreau/Work/pact/pact-node/src/publisher.js:71:12
at Function..map..collect (/home/mboudreau/Work/pact/pact-node/node_modules/underscore/underscore.js:172:24)
at /home/mboudreau/Work/pact/pact-node/src/publisher.js:69:7
at Promise.apply (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:1185:26)
at Promise.promise.promiseDispatch (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:808:41)
at /home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:1411:14
at runSingle (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:137:13)
at flush (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
✓ should report an unsuccessful push
with authentication
and valid credentials
✓ should return a sucessful promise
and invalid credentials
[2017-05-11T15:41:50.481Z] ERROR: [email protected]/17217 on JAX:
Could not publish pacts to broker at "http://localhost:9221/auth":
- Failed http call to pact broker.
URI: http://localhost:9221/auth/pacts/provider/publisher/consumer/consumer/version/1.0.0
Code: 401
Body: Unauthorized
--
Error: Could not publish pacts to broker at "http://localhost:9221/auth":
- Failed http call to pact broker.
URI: http://localhost:9221/auth/pacts/provider/publisher/consumer/consumer/version/1.0.0
Code: 401
Body: Unauthorized
at /home/mboudreau/Work/pact/pact-node/src/publisher.js:89:22
at _fulfilled (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:854:54)
at self.promiseDispatch.done (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:883:30)
at Promise.promise.promiseDispatch (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:816:13)
at /home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:624:44
at runSingle (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:137:13)
at flush (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
✓ should return a rejected promise
when publishing a directory of Pacts to a Broker
and the directory contains only valid Pact contracts
✓ should asynchronously send all Pacts to the Broker
✓ should successfully tag all Pacts sent with 'test' and 'latest'
and the directory contains Pact and non-Pact contracts
✓ should asynchronously send only the Pact contracts to the broker
when publishing Pacts from an http-based URL
and the Pact contracts are valid
✓ should asynchronously send the Pact contracts to the broker
✓ should successfully tag all Pacts sent with 'test' and 'latest'
and the Pact contracts do not exist (404)
[2017-05-11T15:41:50.550Z] ERROR: [email protected]/17217 on JAX:
Could not retrieve all Pact contracts:
- Failed to get Pact contract from broker:
Failed http call to pact broker.
URI: http://localhost:9221/somepacturlthatdoesntexist
Code: 404
Body:



<title>Error</title>


Cannot GET /somepacturlthatdoesntexist


--
Error: Could not retrieve all Pact contracts:
  - Failed to get Pact contract from broker:
Failed http call to pact broker.
URI: http://localhost:9221/somepacturlthatdoesntexist
Code: 404
Body: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /somepacturlthatdoesntexist</pre>
</body>
</html>

    at /home/mboudreau/Work/pact/pact-node/src/publisher.js:63:16
    at _fulfilled (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:854:54)
    at self.promiseDispatch.done (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:883:30)
    at Promise.promise.promiseDispatch (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:816:13)
    at /home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:624:44
    at runSingle (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:137:13)
    at flush (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    ✓ should return a rejected promise
  and the Pact contracts are invalid (no consumer/provider)

[2017-05-11T15:41:50.555Z] ERROR: [email protected]/17217 on JAX: Invalid Pact contract given. Unable to parse consumer and provider name
Error: Invalid Pact contract given. Unable to parse consumer and provider name
at constructPutUrl (/home/mboudreau/Work/pact/pact-node/src/publisher.js:193:9)
at /home/mboudreau/Work/pact/pact-node/src/publisher.js:71:12
at Function..map..collect (/home/mboudreau/Work/pact/pact-node/node_modules/underscore/underscore.js:172:24)
at /home/mboudreau/Work/pact/pact-node/src/publisher.js:69:7
at Promise.apply (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:1185:26)
at Promise.promise.promiseDispatch (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:808:41)
at /home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:1411:14
at runSingle (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:137:13)
at flush (/home/mboudreau/Work/pact/pact-node/node_modules/q/q.js:125:13)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
✓ should return a rejected promise

Verifier Integration Spec
Pact Broker Mock listening on port: 9123
when given a successful contract
without provider states
(node:17217) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:879:in initialize': getaddrinfo: Name or service not known (Faraday::ConnectionFailed) from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:879:in open'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:879:in block in connect' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/timeout.rb:74:in timeout'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:878:in connect' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:863:in do_start'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:852:in start' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:1375:in request'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/ruby/lib/ruby/2.2.0/net/http.rb:1133:in get' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:78:in perform_request'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:38:in block in call' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:85:in with_net_http_connection'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:33:in call' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday_middleware-0.10.1/lib/faraday_middleware/response_middleware.rb:30:in call'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday-0.12.1/lib/faraday/rack_builder.rb:139:in build_response' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday-0.12.1/lib/faraday/connection.rb:386:in run_request'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/faraday-0.12.1/lib/faraday/connection.rb:149:in get' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:108:in get_json_from_server'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:92:in get_json' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:31:in get_pact_consumer_name'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:65:in block in verify_pacts' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:64:in collect'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/app.rb:64:in verify_pacts' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/lib/pact/provider_verifier/cli.rb:21:in verify'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/command.rb:27:in run' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in invoke_command'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor.rb:369:in dispatch' from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/vendor/ruby/2.2.0/gems/thor-0.19.4/lib/thor/base.rb:444:in start'
from /home/mboudreau/Work/pact/pact-node/node_modules/@pact-foundation/pact-provider-verifier-linux-x64/lib/app/pact-provider-verifier.rb:3:in `

'

    ✓ should return a successful promise (1151ms)
  with Provider States
    ✓ should return a successful promise (1058ms)
  with POST data
    ✓ should return a successful promise (1059ms)
  with POST data and regex validation
    ✓ should return a successful promise (1089ms)
when given a failing contract
  ✓ should return a rejected promise (1167ms)
when given multiple successful API calls in a contract
  ✓ should return a successful promise (1114ms)
when given multiple contracts
  from a local file
    ✓ should return a successful promise (1097ms)
  from a Pact Broker
    without authentication
      ✓ should return a successful promise (2430ms)
    with authentication
      and a valid user/password
        ✓ should return a successful promise (7553ms)
      and an invalid user/password
        ✓ should return a rejected promise (951ms)
        ✓ should return the verifier error output in the returned promise (951ms)
when publishing verification results to a Pact Broker
  and there is a valid verification HAL link in the Pact file
    ✓ should return a successful promise (1233ms)
  and there is an invalid verification HAL link in the Pact file
    ✓ should fail with an error (1226ms)

118 passing (50s)

Mock Server not Starting

I'm currently trying to set up pact with an Angular application and Karma. When running the karma test in which the pact is generated, I always get the error "process not found":

Error: Command failed: taskkill /f /t /pid 13344
FEHLER: Der Prozess "13344" wurde nicht gefunden.

    at checkExecSyncError (child_process.js:472:13)
    at Object.execSync (child_process.js:512:13)
    at Server.stop (C:\daten\workspaces\pact-node-test\node_modules\@pact-foundation\pact-node\src\server.js:138:7)
    at Server.<anonymous> (C:\daten\workspaces\pact-node-test\node_modules\@pact-foundation\pact-node\src\server.js:117:8)
    at ChildProcess.g (events.js:292:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:920:16)
    at Socket.<anonymous> (internal/child_process.js:351:11)
    at emitOne (events.js:96:13)

After some digging, I realized this is just a subsequent error to the mock server not starting. With LOGLEVEL set to DEBUG, I get the following log output before the above:

[2017-10-07T14:40:44.300Z] DEBUG: [email protected]/14532 on THEMACHINE:
    : cannot load such file -- bundler/vendor/molinillo/lib/molinillo/modules/specification_provider (LoadError)

So, there are two issues here:

  1. When the mock server isn't starting, an error should be raised so that it's clear what went wrong. That would have saved me some trouble finding the real cause, because I was first looking into the "process not found" error :).
  2. Why do I get the LoadError? Obviously is has something to do with Ruby dependencies not being satisfied, but I'm not (yet) into Ruby enough to find out what's wrong here.

I have prepared a minimal example at https://github.com/thombergs/pact-node-test. Running npm run start I get the above error.

I would appreciate any hints on this issue ;)

Underscores in header keys are changed to hyphens during requests

I have generated an interaction that expects the following request headers:

"headers": {
    "Accept": "application/json",
    "customer_key": "1",
    "tenant_key": "1"
}

When attempting to hit the the wrapper server, headers get transformed into a different format. Partial output from the mock-server-integration logs:

"headers": {
    "Customer-Key": "1",
    "Tenant-Key": "1",
    "Host": "localhost:1234",
    "Accept": "application/json",
    "Connection": "close",
    "Version": "HTTP/1.1"
}

Is there some way to stop this transformation of custom headers with underscores?

The node wrapper should pass the new --sslcert and --sslkey options to server

Two new command line options, --sslcert and --sslkey, were added to the Ruby pact mock service which this library wraps. These options allow you to specify a particular SSL certificate instead of using one that's generated each time. This way you can create a certificate, add it to your computer's list of trusted root certificates, and avoid the SSL errors typically thrown by web browsers. I plan on submitting a PR for this shortly.

pact-foundation/pact-mock_service#56

Pact-broker behind reverse proxy - Unable to publish and verify provider

I have set up pact broker behind a reverse proxy. Getting error while trying to publish and verify the
pact. The same works with non-ssl URL

Pact publish error log :

Could not publish pact:
    Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=error: certificate verify failed /Users/loheswaran_g/Work/wag-src-repo/fork/boilerplate/react-ui-boilerplate/node_modules/@pact-foundation/pact-node/standalone/darwin-1.43.1/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.14.1/lib/pact_broker/client/pacts.rb:35:in `get', attempt 1 of 3

Pact verify provider error log :

Error: the string "Unable to find pacts for given provider 'APIHealthCheckService' and tags ''" was thrown, throw an Error :)
      at tryCatch (node_modules/es6-promise/dist/lib/es6-promise/-internal.js:188:12)
      at invokeCallback (node_modules/es6-promise/dist/lib/es6-promise/-internal.js:203:13)
      at publish (node_modules/es6-promise/dist/lib/es6-promise/-internal.js:177:7)
      at publishRejection (node_modules/es6-promise/dist/lib/es6-promise/-internal.js:118:3)
      at flush (node_modules/es6-promise/dist/lib/es6-promise/asap.js:92:5)
      at _combinedTickCallback (internal/process/next_tick.js:73:7)
      at process._tickCallback (internal/process/next_tick.js:104:9)

Change log

By any chance is there a change log showing what has been committed/what has been resolved in the different versions?

Couldn't start Pact Verifier process with PID

Hi guys, I recently started writing some code to verify pacts. For some reason every time I get "Couldn't start Pact Verifier process with PID: *" even though I've tried cleaning running instances. Any advice you guys could give for getting around this issue? On Mac OS.

Having an error with finalize()

I'm using "pact": "2.2.1" and today I found same code failed with newly npm install.

{"message":"Error ocurred in mock service: NoMethodError - undefined method `each' for #<String:0x2b913e8>","backtrace":["C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/request_decorator.rb:40:in `query'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/request_decorator.rb:20:in `as_json'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/interaction_decorator.rb:18:in `as_json'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_decorator.rb:18:in `block in as_json'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_decorator.rb:18:in `collect'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_decorator.rb:18:in `as_json'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_decorator.rb:26:in `to_json'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/json-2.0.3/lib/json/pure/generator.rb:242:in `generate'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/json-2.0.3/lib/json/common.rb:286:in `pretty_generate'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_writer.rb:66:in `pact_json'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_writer.rb:59:in `update_pactfile'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_writer.rb:52:in `update_pactfile_if_needed'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer_contract/consumer_contract_writer.rb:37:in `write'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/mock_service/request_handlers/pact_post.rb:31:in `respond'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/mock_service/request_handlers/base_request_handler.rb:17:in `call'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/rack-2.0.1/lib/rack/cascade.rb:33:in `block in call'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/rack-2.0.1/lib/rack/cascade.rb:24:in `each'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/rack-2.0.1/lib/rack/cascade.rb:24:in `call'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer/mock_service/cors_origin_header_middleware.rb:11:in `call'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer/mock_service/error_handler.rb:13:in `call'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/mock_service/app.rb:32:in `call'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/app/lib/pact/consumer/mock_service/set_location.rb:14:in `call'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/rack-2.0.1/lib/rack/handler/webrick.rb:86:in `service'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:138:in `service'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:94:in `run'","C:/Projects/ei-site-api-debug/ei-site-api/src/node_modules/@pact-foundation/pact-mock-service-win32/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread'

This error was introduced between 3 days ago to today.
I compared the \node_modules@pact-foundation\pact-node\package.json in two copies and find difference:

    "@pact-foundation/pact-mock-service": "0.10.x",
    "@pact-foundation/pact-provider-verifier": "0.1.x",
    "@pact-foundation/pact-mock-service": "1.x.x",
    "@pact-foundation/pact-provider-verifier": "1.x.x",

Having the same issue with pact version "pact": "2.3.4"
Could anyone please help have a look?

TypeScript compilation fails due to missing type definitions

This is a carry on from pact-foundation/pact-js#142

Software versions

  • OS: Ubuntu 16.04.3 LTS
  • Consumer Pact library: PactJS 5.3.1
  • Node Version: v6.9.1

Expected behaviour

When using pact-js as a devDependency, pact-js can be compiled by TypeScript successfully without requiring additional definitions (e.g. adding @types/bunyan as an explicit dependency).

Actual behaviour

TypeScript compilation fails.

Steps to reproduce

  1. Clone/Download https://gist.github.com/zsims/904dcb7d7fcc2543776740be65b171c0
  2. yarn install (or npm install)
  3. yarn test (or npm test)

Relevant log files

$ yarn run test
yarn run v1.3.2
$ tsc
node_modules/@pact-foundation/pact-node/src/logger.ts(11,8): error TS2339: Property 'info' does not exist on type 'Logger'.
node_modules/@pact-foundation/pact-node/src/logger.ts(19,36): error TS2339: Property 'level' does not exist on type 'Logger'.
node_modules/@pact-foundation/pact-node/src/logger.ts(25,16): error TS2554: Expected 0 arguments, but got 1.
node_modules/@pact-foundation/pact-node/src/publisher.ts(10,3): error TS2322: Type '{}' is not assignable to type 'PublisherOptions'.
  Property 'pactFilesOrDirs' is missing in type '{}'.
error Command failed with exit code 2.

Pact Download Location config is not working

Thank you for providing Pact as so wonderful a contract testing tool. But we got some problems when working with it.

Our team was spiking pact and decided to use pact as our contract test tool. As we need to deploy our project to an internal machine, it can't access github releases to get the binaries needed by pact-node when running npm install. I was very happy when I saw there was a configuration to solve this problem.

But when I set the config following the introduction from https://github.com/pact-foundation/pact-node/blob/master/README.md#pact-download-location, it still downloaded the binaries from github.

This made me very confused, so I digged into the code here https://github.com/pact-foundation/pact-node/blob/master/standalone/install.ts, and found that findPackageConfig() changed PACT_BINARY_LOCATION after const BINARIES had already set!

I also run node postinstall.js locally and printed console log, then got the following result:

findPackageConfig: tries: undefined
PACT_BINARY_LOCATION: https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.47.2/
-----------------
findPackageConfig: tries: 9
PACT_BINARY_LOCATION: https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.47.2/
-----------------
findPackageConfig: tries: 8
PACT_BINARY_LOCATION: https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.47.2/
----------setup-----------
---------download---------
Installing Pact Standalone Binary for darwin.
Downloading Pact Standalone Binary v1.47.2 for platform darwin from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.47.2/pact-1.47.2-osx.tar.gz
Please note: we are tracking this download anonymously to gather important usage statistics. To disable tracking, set 'pact_do_not_track: true' in your package.json 'config' section.
Downloaded 0.21%...
Downloaded 0.89%...
Downloaded 2.95%...

It showed that it started to download the binaries just while the findPackageConfig working hadn't finished. So the config for pact_binary_location doesn't work at all!

versions:
"@pact-foundation/pact" : "5.9.1",
"@pact-foundation/pact-node": "6.19.2"

Hope get your feedback soon.

Thank you!

Publisher fails when broker returns 201 response

In v4.4.3 the Publisher will fail if the Pact broker returns a 201 response.

See publisher.js:132 - the response is being explicitly checked for a 200 even though the broker can return a 201 CREATED response.

Allow 'format' to be specified when calling pact-ruby-standalone

In my provider project, I'm interested in presenting the results in a different format (e.g. having multiple mocha tests for each thing tested, rather than a large single test).

Taking a look at how I could parse the output from verifyProvider, I noticed that the underlying binary (pact-ruby-standalone) allows a --format flag to be passed, with JSON available as one of the outputs.

I have quickly put together a proof of concept here: #86 . By not appending the stderr output to the string (due to it adding INFO lines), and by specifying the format to be json, I was able to parse the JSON response.

I'd be happy to work on implementing this feature fully beyond the proof of concept (e.g. agree on what the options should be called, adding in tests etc.)

pact-node fails to launch mock server on windows

We are using pact-node (v6.16.0) bundled with pact-karma (2.1.5) and pact-web (5.9.0)

When trying to run the pact tests on a windows machine, I'm seeing the following error

[2018-05-07T22:23:19.539Z]  INFO: [email protected]/7872 on xxxxxx: Created 'standalone\win32-1.38.0\bin\pact-mock-service.bat service --port '3110' --consumer 'consumer' --prov
ider 'provider' --log 'C:\.....\pacts\stubserver-integration.log' --pact_dir '.....\pacts' --pact-file-writ
e-mode 'overwrite' --host 'localhost'' process with PID: 8688
[2018-05-07T22:23:24.034Z]  WARN: [email protected]/7872 on xxxxxx: Pact exited with code 1.
[2018-05-07T22:23:24.036Z]  INFO: [email protected]/7872 on xxxxxx: Removing Pact with PID: 8688
ERROR: The process "8688" not found.

When trying to run that bat file directly, I get the following error

C:\.....\node_modules\@pact-foundation\pact-node\standalone\win32-1.38.0\bin>pact-mock-service.bat
C:\.....\node_modules\@pact-foundation\pact-node\standalone\win32-1.38.0\lib\ruby\bin\..\bin.real\ruby.exe: No such file or directory -- UI (LoadError)

Any pointers on why this is happening?

verifyProvider is adding a `Host` header of `example.org` when running a contract

When verifyProvider is run with a contract, a header of "Host":"example.org" is being added to the request that gets sent to the provider. One of my services is failing its contract because of this, as it can't handle the header.

For example, when I run this contract:

{
  "consumer": {
    "name": "myconsumer"
  },
  "provider": {
    "name": "myprovider"
  },
  "interactions": [
    {
      "description": "A simple request",
      "providerState": "the service is up",
      "request": {
        "method": "get",
        "path": "/"
      },
      "response": {
        "status": 200
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}

The actual request that gets sent has these headers:

Host: example.org
Cookie:
X-Forwarded-For: 127.0.0.1
Content-Length: 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.