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

Added self-contained http/network requests implementation #1121

Merged
merged 21 commits into from
Oct 20, 2021

Conversation

Ice3man543
Copy link
Member

@Ice3man543 Ice3man543 commented Oct 14, 2021

This PR resolves #1086 by adding a new attribute to HTTP requests that marks all the HTTP Requests in that template as self-sufficient, meaning they do not require any input to be executed.

Few examples are provided below. The attribute was added to HTTP requests as the implementation was only relevant for HTTP.

id: example-self-contained-input

info:
  name: example-self-contained
  author: pdteam
  severity: info

self-contained: true
requests:
  - raw:
      - |
        GET https://example.com:443/gg HTTP/1.1
        Host: example.com:443

    matchers:
      - type: status
        status:
          - 302
id: example-self-contained-input-2

info:
  name: example-self-contained-input-2
  author: pdteam
  severity: info

self-contained: true
requests:
  - path:
      - "https://example.com:443/gg" 
    matchers:
      - type: status
        status:
          - 302
id: api-sendgrid

info:
  name: Sendgrid API Test
  author: zzeitlin
  reference: https://docs.sendgrid.com/for-developers/sending-email/getting-started-smtp
  severity: info
  tags: token-spray,sendgrid

self-contained: true
network:
  - inputs:
      - data: "ehlo\r\n"
        read: 1024
      - data: "AUTH PLAIN {{base64(hex_decode('00')+'apikey'+hex_decode('00')+token)}}\r\n"
        read: 1024
    host:
      - "tls://smtp.sendgrid.net:465"

    matchers:
      - type: word
        words:
          - "Authentication successful"

Copy link
Member

@ehsandeep ehsandeep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Host header is not considered in RAW format compared to base format, additionally, we can extend this support for network templates as well.

Base format:-

id: example-self-contained-input-2

info:
  name: example-self-contained-input-2
  author: pdteam
  severity: info

self-contained: true
requests:
  - path:
      - "https://example.com/gg"
    headers:
      Host: "{{randstr}}.tld"

    matchers:
      - type: status
        status:
          - 302

RAW format:-

id: example-self-contained-input

info:
  name: example-self-contained
  author: pdteam
  severity: info

self-contained: true
requests:
  - raw:
      - |
        GET https://example.com/gg HTTP/1.1
        Host: {{randstr}}.tld


    matchers:
      - type: status
        status:
          - 302

@ehsandeep ehsandeep added the Status: In Progress This issue is being worked on, and has someone assigned. label Oct 15, 2021
@Ice3man543 Ice3man543 changed the title Added self-contained http requests implementation Added self-contained http/network requests implementation Oct 17, 2021
@Ice3man543
Copy link
Member Author

Ice3man543 commented Oct 17, 2021

Added the support to network requests as well which is now possible after the merge of #1138.

id: api-sendgrid

info:
  name: Sendgrid API Test
  author: zzeitlin
  reference: https://docs.sendgrid.com/for-developers/sending-email/getting-started-smtp
  severity: info
  tags: token-spray,sendgrid

self-contained: true
network:
  - inputs:
      - data: "ehlo\r\n"
        read: 1024
      - data: "AUTH PLAIN {{base64(hex_decode('00')+'apikey'+hex_decode('00')+token)}}\r\n"
        read: 1024
    host:
      - "tls://smtp.sendgrid.net:465"

    matchers:
      - type: word
        words:
          - "Authentication successful"

@ehsandeep ehsandeep mentioned this pull request Oct 17, 2021
2 tasks
@ehsandeep ehsandeep added Status: Completed Nothing further to be done with this issue. Awaiting to be closed. and removed Status: In Progress This issue is being worked on, and has someone assigned. labels Oct 18, 2021
@ehsandeep ehsandeep linked an issue Oct 18, 2021 that may be closed by this pull request
Copy link
Contributor

@forgedhallpass forgedhallpass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in my previous comment (#1086 (comment)), I believe the self-contained attribute should be declared per-template level and not per-request etc.

v2/pkg/protocols/network/network.go Outdated Show resolved Hide resolved
v2/pkg/protocols/network/request.go Show resolved Hide resolved
v2/pkg/protocols/network/request.go Show resolved Hide resolved
@Ice3man543
Copy link
Member Author

Changed it to be per-template instead.

id: example-self-contained-input

info:
  name: example-self-contained
  author: pdteam
  severity: info


self-contained: true
requests:
  - raw:
      - |
        GET https://example.com/gg HTTP/1.1
        Host: {{randstr}}.tld

    matchers:
      - type: status
        status:
          - 302

@ehsandeep ehsandeep merged commit 52382df into dev Oct 20, 2021
@ehsandeep ehsandeep removed the request for review from Mzack9999 October 20, 2021 15:24
@ehsandeep ehsandeep linked an issue Oct 20, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Completed Nothing further to be done with this issue. Awaiting to be closed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set null value to target/u flag in not provided [feature] Support to define host in the template itslef
3 participants