Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAS: An invalid HAR Request is produced when path item object contains properties other than http methods #242

Closed
ostridm opened this issue Apr 22, 2024 · 0 comments · Fixed by #243
Assignees
Labels
Type: bug Something isn't working.

Comments

@ostridm
Copy link
Contributor

ostridm commented Apr 22, 2024

Description

Converting of some specifications to HAR results in having an invalid HAR Request, when path item object has parameters or servers properties specified.

Proposed solution

Filter out all the properties other than http methods according to the specification

Steps to reproduce

Pass the my-schema.yaml (see below) to the oas2har as follows:

import { oas2har } from '@har-sdk/oas';
import { readFile } from 'fs';
import { promisify } from 'util';
import { load } from 'js-yaml';

const content = await promisify(readFile)(
  './my-schema.yaml',
  'utf8'
);

const result = oas2har(load(content) as OpenAPIV2.Document);
my-schema.yaml
openapi: 3.0.1
info:
  title: OWASP crAPI API
  version: 1-oas3
externalDocs:
  description: Completely Ridiculous API (crAPI)
  url: https://github.com/OWASP/crAPI
servers:
  - url: http://localhost:8888
paths:
  /identity/api/auth/signup:
    post:
      operationId: signup
      summary: Sign up
      description: Used to create an account
      tags:
        - Identity / Auth
      security: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - name
                - number
                - password
              properties:
                email:
                  type: string
                  example: Cristobal.Weissnat@example.com
                name:
                  type: string
                  example: Cristobal.Weissnat
                number:
                  type: string
                  example: '6915656974'
                password:
                  type: string
                  example: 5hmb0gvyC__hVQg
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CRAPIResponse'
          description: ''
    parameters: []
components:
  schemas:
    CRAPIResponse:
      type: object
      properties:
        message:
          type: string
        status:
          type: integer
          format: int32

Actual result

An invalid request produced containing PARAMETERS as http method value

my-schema.har
[
  {
    "queryString": [],
    "cookies": [],
    "method": "PARAMETERS",
    "headers": [],
    "httpVersion": "HTTP/1.1",
    "headersSize": 0,
    "bodySize": 0,
    "url": "http://3.83.224.235:8888/identity/api/auth/signup"
  },
  {
    "queryString": [],
    "cookies": [],
    "method": "POST",
    "headers": [
      {
        "value": "application/json",
        "name": "content-type"
      },
      {
        "value": "application/json",
        "name": "accept"
      }
    ],
    "httpVersion": "HTTP/1.1",
    "headersSize": 0,
    "bodySize": 0,
    "postData": {
      "mimeType": "application/json",
      "text": "{\"email\":\"test@example.com\",\"password\":\"Test!123\"}"
    },
    "url": "http://3.83.224.235:8888/identity/api/auth/login"
  }
]

Expected result

PARAMETERS request is omitted

my-schema.har
[
  {
    "bodySize": 0,
    "cookies": [],
    "headers": [
      {
        "name": "content-type",
        "value": "application/json"
      },
      {
        "name": "accept",
        "value": "application/json"
      }
    ],
    "headersSize": 0,
    "httpVersion": "HTTP/1.1",
    "method": "POST",
    "postData": {
      "mimeType": "application/json",
      "text": "{\"email\":\"Cristobal.Weissnat@example.com\",\"name\":\"Cristobal.Weissnat\",\"number\":\"6915656974\",\"password\":\"5hmb0gvyC__hVQg\"}"
    },
    "queryString": [],
    "url": "http://localhost:8888/identity/api/auth/signup"
  }
]
@ostridm ostridm added the Type: bug Something isn't working. label Apr 22, 2024
@ostridm ostridm self-assigned this Apr 22, 2024
@ostridm ostridm changed the title OAS: An invalid HAR Entry is produced when path item object contains properties other than http methods OAS: An invalid HAR Request is produced when path item object contains properties other than http methods Apr 22, 2024
ostridm added a commit that referenced this issue Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug Something isn't working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant