pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.63k stars 348 forks source link

Allow pact-js to pass the new --sslcert and --sslkey options to mock server #29

Closed mefellows closed 7 years ago

mefellows commented 7 years ago

See https://github.com/pact-foundation/pact-node/issues/27

Blackbaud-AlexKingman commented 7 years ago

Thanks for this! 👍

mefellows commented 7 years ago

v2.2.0 should publish in the next half an hour or so. Should get you up and going!

ekaitzht commented 6 years ago

@mefellows If i create my provider with sslcerts:

exports.backendSelfSignedPactConfig = {
    ...commonConfigPact,
    ssl: true,
    port: 12347,
    sslcert: path.join(__dirname, '/certs/self-signed/server-crt.pem'),
    sslkey: path.join(__dirname, '/certs/self-signed/server-key.pem')
};

POST data to mock service

{
    method: 'POST',
    url: 'https://localhost:12347/success',
    data: < Buffer 7 b 22 38 29 > ,
    headers: {
        'accept-encoding': 'gzip, deflate',
        'user-agent': 'node-superagent/2.3.0',
        'content-type': 'application/json',
        authorization: 'Bearer asfdsdf-asdf-sdfas-asdf-234asdf234234',
        'content-length': '35',
        connection: 'close'
    },
    validateStatus: [Function: validateStatus],
    httpsAgent: Agent {
        domain: null,
        _events: {
            free: [Function]
        },
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: {
            ca: [Object],
            path: null
        },
        requests: {},
        sockets: {},
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        maxCachedSessions: 100,
        _sessionCache: {
            map: {},
            list: []
        }
    }
}

[Object] is coming from here->  fs.readFileSync(path.join(__dirname, '/certs/self-signed/ca-crt.pem'))

Versions: @pact-foundation/pact": "^5.3.0" -> "@pact-foundation/pact-node": "^6.5.0"

Then I do client request from nodejs to that mock server and always is working it doesn't matter that the certificates are invalid (expired, wrong keys etc) never the test is broke.

What can be happening? @

mefellows commented 6 years ago

So you have provided the mock service with invalid certificates and are expecting the calls to fail?

I'll check in our code, it's possible we're setting the session to allow insecure SSL as this is probably the common case here.

What are you expecting and what would you like to see changed?

mefellows commented 6 years ago

I wonder if this is why https://github.com/pact-foundation/pact-node/blob/master/bin/pact-cli.spec.ts#L208

@mboudreau - feels like this should be behind a flag and something a user has control over?