Code Monkey home page Code Monkey logo

Comments (8)

mishushakov avatar mishushakov commented on June 8, 2024

Thanks for leaving the issue and sorry for the wait. Will be investigating tomorrow

from stepci.

mishushakov avatar mishushakov commented on June 8, 2024

Wanted to come back to this. There's no Location check in Step CI.
Could you clarify what you want to accomplish with the check?

from stepci.

muffl0n avatar muffl0n commented on June 8, 2024

I'm sorry, my example was buggy. Correct code for the check would be

          check:
            status: 301
            headers:
              Location: /foo

I'm not sure why I posted this, must have been copying from a wrong file.
Let me check tomorrow at work if this error I described is caused by my wrong code.

from stepci.

mishushakov avatar mishushakov commented on June 8, 2024

Are you sure https://httpbin.org/redirect-to?url=/foo&status_code=301 has a Location header?

from stepci.

mishushakov avatar mishushakov commented on June 8, 2024

This is the response I get when I request it with my regular http client

HTTP/1.1 404 NOT FOUND
Date: Tue, 18 Apr 2023 15:42:54 GMT
Content-Type: text/html
Content-Length: 233
Connection: close
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

from stepci.

muffl0n avatar muffl0n commented on June 8, 2024

Are you sure you are using the correct URL?

# http -p h https://httpbin.org/redirect-to\?url\=/foo\&status_code\=301            
HTTP/1.1 301 MOVED PERMANENTLY
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 0
Content-Type: text/html; charset=utf-8
Date: Tue, 18 Apr 2023 15:44:37 GMT
Location: /foo
Server: gunicorn/19.9.0

from stepci.

mishushakov avatar mishushakov commented on June 8, 2024

Have you tried checking redirects using redirects check?

https://docs.stepci.com/reference/workflow-syntax.html#tests-test-steps-step-http-check-redirects

Example for your case would be:

check:
  redirects:
    - foo/

or

check:
  redirects:
    - https://httpbin.org/foo/

from stepci.

muffl0n avatar muffl0n commented on June 8, 2024

Thanks for your hint! I revisited my testcase:

version: "1.1"
name: redirect
config:
  continueOnFail: true
tests:
  redirect:
    steps:
      - name: httpbin
        http:
          url: https://httpbin.org/redirect-to?url=/foo&status_code=301
          method: GET
          check:
            headers:
              Location: /foo
            redirects:
              - /foo
      - name: httpbin
        http:
          url: https://httpbin.org/redirect-to?url=/foo&status_code=301
          method: GET
          followRedirects: false
          check:
            headers:
              Location: /foo
            redirects:
              - /foo

this is the result

 FAIL  redirect

Summary

  ✕ httpbin failed after 0.892s
  ✕ httpbin failed after 0.408s

● redirect › httpbin

Request  HTTP 

GET https://httpbin.org/foo HTTP/1.1

Response

HTTP/1.1 404 NOT FOUND
date: Wed 19 Apr 2023 06:53:41 GMT
content-type: text/html
content-length: 233
connection: close
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>


Checks

Headers

  ✕ Location: undefined (expected /foo)

undefined

  ✕ https://httpbin.org/foo (expected /foo)

● redirect › httpbin

Request  HTTP 

GET https://httpbin.org/redirect-to?url=/foo&status_code=301 HTTP/1.1

Response

HTTP/1.1 301 MOVED PERMANENTLY
date: Wed 19 Apr 2023 06:53:41 GMT
content-type: text/html; charset=utf-8
content-length: 0
connection: close
server: gunicorn/19.9.0
location: /foo
access-control-allow-origin: *
access-control-allow-credentials: true



Checks

Headers

  ✔ Location: /foo

undefined

  ✕  (expected /foo)

Tests: 1 failed, 0 passed, 1 total
Steps: 2 failed, 0 skipped, 0 passed, 2 total
Time:  1.888s, estimated 2s
CO2:   0.00008g

Workflow failed after 1.888s

So it seems to me, that the redirects check does not check for the Location header, but simply follows all redirects and grabs the resulting URL, right? I couldn't confirm this in the runner's code, unfortunately.
So to check explicitly for the answer of the first redirect, I still have to set followRedirects: false and can't use the check redirects but have to check for the header Location.

To come back to the original topic of this issue:

version: "1.1"
name: redirect
config:
  continueOnFail: true
tests:
  redirect:
    steps:
      - name: httpbin
        http:
          url: https://httpbin.org/redirect-to?url=/foo&status_code=301
          method: GET
          followRedirects: false
          check:
            headers:
              Location: /foo/

This check should fail, cause the header Location contains the string /foo. That should not match /foo/.

from stepci.

Related Issues (20)

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.