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

[Bug]: Check "Location" does not check properly #130

Open
1 task
muffl0n opened this issue Apr 11, 2023 · 9 comments
Open
1 task

[Bug]: Check "Location" does not check properly #130

muffl0n opened this issue Apr 11, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@muffl0n
Copy link

muffl0n commented Apr 11, 2023

What happened?

Given a call to httpbin.org, which returns a redirect to /foo:

-> % curl -I "https://httpbin.org/redirect-to?url=/foo&status_code=301"
HTTP/2 301 
date: Tue, 11 Apr 2023 13:35:11 GMT
content-type: text/html; charset=utf-8
content-length: 0
server: gunicorn/19.9.0
location: /foo
access-control-allow-origin: *
access-control-allow-credentials: true
version: "1.1"
name: redirect
tests:
  redirect:
    steps:
      - name: success
        http:
          url: https://httpbin.org/redirect-to?url=/foo&status_code=301
          method: GET
          followRedirects: false
          check:
            status: 301
            Location: /foo
      - name: fail
        http:
          url: https://httpbin.org/redirect-to?url=/foo&status_code=301
          method: GET
          followRedirects: false
          check:
            status: 301
            Location: /foo/

Both steps pass:

 PASS  redirect

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

Workflow passed after 1.715s

What did you expect to happen?

I'd expect, that the first step would pass, second test would fail.
/foo and /foo/ is clearly not the same URL.

Version

2.6.6

Environment

v19.8.1

How can we reproduce this bug?

No response

Relevant log output

No response

Would you be interested in working on a bugfix for this issue?

  • Yes! Assign me
@muffl0n muffl0n added the bug Something isn't working label Apr 11, 2023
@mishushakov
Copy link
Member

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

@mishushakov
Copy link
Member

mishushakov commented Apr 18, 2023

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?

@muffl0n
Copy link
Author

muffl0n commented Apr 18, 2023

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.

@mishushakov
Copy link
Member

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

@mishushakov
Copy link
Member

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>

@muffl0n
Copy link
Author

muffl0n commented Apr 18, 2023

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

@mishushakov
Copy link
Member

mishushakov commented Apr 18, 2023

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/

@muffl0n
Copy link
Author

muffl0n commented Apr 19, 2023

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/.

@mishushakov
Copy link
Member

mishushakov commented Feb 14, 2024

Hey Sven,
The reason it wasn't failing is because everything starting with / in Step CI is treated as regex (in checks).

/foo/ matches /foo

Here's what you could have done:

Location: /foo/

Matches regex /foo/

Location:
  eq: /foo/

Equality comparison (==)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants