Git Product home page Git Product logo

just-api's Issues

SSL error on reading https endpoint

Hi!

I get the following error when access a https endpoint

Error: write EPROTO 140263490227968:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl/record/rec_layer_s3.c:1407:SSL alert number 40

    at _errnoException (util.js:992:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:864:14)

My configuration looks like -

meta:
  name: GraphQL API
configuration:
  host: api.example.com
  scheme: https
  port: 8443
specs:
  - name: Get list of all users
    request:
      method: post
      path: /graphql
      headers:
        - name: content-type
          value: application/json
      payload:
        body:
          type: json
          content:
            query: >
                   {
                       getUser(id: "xxxx-xxxx-xxxx-xxxx-xxxxx70cc6d7"){
                        first_name
                        }
                    }
            variables: null
            operationName: null
    response:
      status_code: 200
      json_data:
        - path: $.data.getUser.first_name
          value: "John"

The server has a valid SSL certificate signed by a CA.

[Feature request] Make just-api a module

Could be useful to use just-api like a library. In my case, I craft programmatically some YAML files before running the tests. Right now is a 2 steps procedure, but would be more natural to use it in the same program.

DISCLAIMER: I'm completely new to NodeJS, so if I'm saying something stupid, please correct me ๐Ÿ˜„

Enhancement: allow JSON pointer to schema within file

Use Case

An OpenAPI (FKA Swagger) spec often contains multiple schema definitions, such as #/components/responses/someResponseName

It would be very useful to reuse schema definitions from within the existing files, such as:

specs:
  - name: Some request
    ...
    response:
      json_schema:
        type: file
        $ref: schemas/openapi.json#/components/responses/NotFoundError

This would read the __dirname/schemas/openapi.json and extract the components.responses.NotFoundError property.

I can probably submit a contribution for this but would like to collect thoughts to make sure I implement it correctly.

Is it possible to use just-api as a library ?

Wondering if it's possible to import just-api as a library into a React project. I would like to use 'just-api but create a UI dashboard, which would mean saving test states and tests in some DB and other usability features.

if yes are where can I find public API's? Thanks for the great work!

Cannot send binary payload

It seams impossible to send binary payload.
I have directly checked following example:

  - name: post binary data (file) as body
    request:
      path: /echoBinaryBodyResponseStats
      method: post
      headers:
        - name: content-type
          value: image/png
      payload:
          body:
            type: binary
            content: static/assets/logo.png
    response:
      status_code: 200
      json_data:
        - path: $.request_content_size
          value: 12371

And it sends [object Object] as body payload.
Further inspection show that it's a fs.ReadStream object (created in spec.js:515?).
Did I missconfigured something or is it a bug or not fully implemented feature?

Tested with node13 and [email protected].

Intersuite dependencies at level 3 or more of nesting

Hello @kiranz!

Am really enjoying trying out this tool for a Proof of Concept. Thank you for this!

I think I've read all (or most) of your documentation but have not figured it out. If a have a multi-level dependency set up where a test A in one suite A needs to first call a test B in another suite B, which in turn needs to call a test C in yet another suite C...can I just sort of "chain" them like that and test A in suite A only has to worry about calling/using the test B in suite B and assume that the test B will automatically take care of using/calling test C?

Test C is for authenticating and getting a token. Test B is for getting some default values that will be used across all other numerous tests and suites, such as those in suite A.

Or does it mean that tests in Suite A has to explicitly call both the dependency test B as well as explicitly call/use the dependency in test C?

Again, thanks for this tool and your time! I am not a JS developer so this sort of helps us bridge that gap w/ the actual Dev team.

runSpec doesn't execute before_test

When you call this.runSpec in before_test, the test you are executing in runSpec isn't running the before_test functionality.

Example:

meta:
  name: "Test suite"
configuration:
  scheme: "https"
  custom_configuration:
    run_type: inline
    inline:
      function: !!js/function >
        function() {
          this.host = process.env.API_URL;
        }
specs:
  - name: "Get Authorization Token"
    enabled: false
    before_test:
      run_type: inline
      inline:
        function: !!js/function >
          function() {
            this.test.payload = { body: {type: 'json', content: {
                email: process.env.EMAIL,
                password: process.env.PASS
             } } };
          }
    request:
      path: "/api/token"
      method: "post"
      headers:
        - name: content-type
          value: application/json
    response:
      status_code: 201
  - name: "Get List"
    before_test:
      run_type: inline
      inline:
        function: !js/asyncFunction >
          async function() {
            var response = await this.runSpec('Get Authorization Token');
            var tokenResponse = JSON.parse(response.body);
            this.test.headers = { Authorization: tokenResponse.token };
          }
    request:
      path: "/api/users"
      method: "get"
    response:
      status_code: 200
      headers:
        - name: "content-type"
          value: !!js/regexp application/json
      json_data:
        - path: "$.name"
          value: "John Smith"

Desired functionality is for test to get the authorization token and set it as the header instead the following error is outputted:

 1) Get List (/test.yml)
BeforeTestHookError: RequestBodyNotFoundError - request content-type is application/json, but request body is not found
    at Spec.runHook (/node_modules/just-api/src/spec.js:312:19)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
    at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:51:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:804:11)
    at internal/main/run_main_module.js:21:11

Post request common_headers ignored when asserting Content-Type header

Example Test Case

meta:
  name: Testing headers
  enabled: true
  version: "1.0"
configuration:
  scheme: http
  host: 127.0.0.1
  port: 3027
  common_headers:
    - name: customsuiteheader
      value: custom-suite-header-value
    - name: content-type
      value: application/json
specs:
  - name: uses suite-level content-type header
    request:
      path: /echoJSONBodyResponse
      method: post
      payload:
          body:
              type: json
              content:
                  name: Kiran
    response:
        status_code: 200

Actual Behavior

Request method is post,request body is provided but Content-Type header is not provided

Expected Behavior

Suite-level common_headers should be checked when this assertion runs.

Failing tests in master: otherverbs and urlencodedformpost

A few tests are failing in master:

  150 passing (34s)
  2 failing

  1) Other verbs
       "before all" hook:

      AssertionError: expected 1 to equal 0
      + expected - actual

      -1
      +0
      
      at Context.<anonymous> (test/cli/otherverbs.spec.js:13:36)

  2) url encoded form post
       "before all" hook:

      AssertionError: expected 0 to equal 1
      + expected - actual

      -0
      +1
      
      at Context.<anonymous> (test/cli/urlencodedformpost.spec.js:21:48)

Error evaluating graphql response for multiple fields similar to rest api response

I'm trying to use just-api with graphql. For a graphql query for a single query and response, just-api works

But for graphql multiple field query and response similar to the rest-api example below -
https://github.com/kiranz/just-api/blob/master/test/cli/src/suites/jsondata.suite.yml
json-api does not work.

Here is my graphql query -

{
  getAddress(id: "xxx-xxx-xxx") {
    zip
    name
    locality
    country
  }
}

and I would like to evaluate the response for all the fields.

just-api throws the following error for multi-response data -


0 skipped, 2 failed, 0 passed (2 tests)
0 skipped, 1 failed, 0 passed (1 suites)
Duration: 2.4s

Failures:

 1) Get list of all properties (/home/mrcasablr/src/just-api/api-example.yml)
ResponseJSONDataMismatchError: JSON path evaluated value did not match with expected value, json path: $.data.getAddress.zip, Actual value: undefined, Expected value: 90047 
 request: POST https://api.example.com:8443/graphql
    at Spec._validateJSONData (/home/mrcasablr/node_modules/just-api/src/spec.js:699:27)
    at Spec.validateResponse (/home/mrcasablr/node_modules/just-api/src/spec.js:333:18)
    at Spec.runAsTest (/home/mrcasablr/node_modules/just-api/src/spec.js:123:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)

 2) validate json response with json data functionality - should fail (/home/mrcasablr/src/just-api/api-example.yml)
ResponseJSONDataMismatchError: JSON path evaluated value did not match with expected value, json path: $.data.getAddress.location, Actual value: undefined, Expected value: "New England" 
 request: POST https://api.example.com:8443/graphql
    at Spec._validateJSONData (/home/mrcasablr/node_modules/just-api/src/spec.js:699:27)
    at Spec.validateResponse (/home/mrcasablr/node_modules/just-api/src/spec.js:333:18)
    at Spec.runAsTest (/home/mrcasablr/node_modules/just-api/src/spec.js:123:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)

A spec MUST have a request and response minimally?

Hi again,

I am wondering...is it (or not) possible to separate a request from a response and have them reside in separate YML files? I am guessing not but wanted to confirm.

I specifically call it not a Spec because that term insinuates that it is a test. When it comes to intradependencies across suites...does the response part of a dependency also get executed and that spec is being called from another suite?

Thanks again!

Difference in execution plan depending on how spec is called?

Hello,

I am struggling to use just-api for more advanced requests and workflows. Surely I don't understand fully how to use it. Is a spec, or a test, run differently depending on whether the spect itself is being run directly, i.e. it is the spec of interest, versus when said spec is being called from another spec in a different suite, or even if the spec is in the same suite but is a different spec?

If a spec A that has a before_test hook gets called from another spec B in the same suite, does the before_test hook of spec A also get executed? Or are test-context hooks only exercised when the spec/test itself that the hook pertains to gets executed itself?

Please advise...I have been beating my head at this for numerous hours. It's been slooow progress :)

Thanks!

Allow GraphQL request body to be a file path

At the moment it seems like only binary content can be provided as a file path.

For some requests, e.g. GraphQL to properly check coverage, the query might be > 1000 lines, and the schema might cover 100s of Query and Mutation endpoints. It's completely impractical to paste the raw query in every single spec file.

Using the example from the readme:

meta:
  name: GraphQL location service
configuration:
  host: api.graphloc.com
  scheme: https
specs:
  - name: Get Location of a given ip address
    request:
      method: post
      path: /graphql
      headers:
        - name: content-type
          value: application/json
      payload:
        body:
          type: json
          content:
            query: >
                   {
                    getLocation(ip: "8.8.8.8") {
                      country {
                        iso_code
                      }
                     }
                    }
            variables: null
            operationName: null
    response:
      status_code: 200
      json_data:
        - path: $.data.getLocation.country.iso_code
          value: US

It would be very useful for payload.body.content.query to be a file path rather than an inline query.

Cannot add proxy, hence cannot intercept requests

Adding a proxy to the tool would be really beneficial since one can then intercept outgoing requests. Currently, I cannot find a way to troubleshoot what went wrong. I've created a spec file to validate a json response schema -> executed it but the request failed with 400 Bad Request, proxying the request to a proxy would be really easy to see what one is sending and then change the request accordingly.

Suite custom_configuration from module ignores common_headers

Steps to reproduce

configuration:
  custom_configuration:
    run_type: module
    module:
      module_path: some-module.js
      function_name: suiteConfigSync
specs:
  - name: uses suite-level custom_configuration content-type header
    request:
      path: /echoJSONBodyResponse
      method: post
      payload:
          body:
              type: json
              content:
                  name: Kiran
    response:
        status_code: 200
module.exports = {
  suiteConfigSync: function() {
    this.common_headers = [{
      name: 'content-type',
      value: 'application/json'
    }];
  }
};

Actual Behavior

InvalidRequestHeaderError: Request method is post,request body is provided but Content-Type header is not provided

Expected Behavior

common_headers should be honored

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.