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

Possibility to use lokal settings #682

Open
Woribe opened this issue Jan 8, 2025 · 3 comments
Open

Possibility to use lokal settings #682

Woribe opened this issue Jan 8, 2025 · 3 comments

Comments

@Woribe
Copy link

Woribe commented Jan 8, 2025

Im using Verify.Http for my integrationtests using the webapplicationfactory framework.
Im building a fetered authentication application that uses jwt's.
Some of the endpoints relais heavly on headers and some less.

For example my login-endpoint sets a httponly jwt.
So I would like to have my test verify that the responsemessage contains headers like this, where the response headers clealy contains a "Set-Cookie":

{
  Version: 1.1,
  Content: {
    Headers: [
      {
        Content-Type: [
          application/json; charset=utf-8
        ]
      }
    ]
  },
  StatusCode: OK,
  ReasonPhrase: OK,
  Headers: [
    {
      Set-Cookie: [
        jwt=REDACTED
      ]
    }
  ],
  TrailingHeaders: [],
  RequestMessage: {
    Version: 1.1,
    Content: {
      Headers: [
        {
          Content-Type: [
            application/json; charset=utf-8
          ]
        },
        {
          Content-Length: [
            59
          ]
        }
      ]
    },
    Method: {
      Method: POST
    },
    RequestUri: http://localhost/api/Authentication/Login,
    Headers: []
  },
  IsSuccessStatusCode: true
}

When im doing VerifyHttp.Initialize(); some converters is set on the global VerifierSettings which simplifies the headers.
This means that when im trying to verify the response of my login endpoint, im left with a response that looks like this:

{
  "Version": "1.1",
  "Status": "200 OK",
  "Cookies": {
    "jwt": "REDACTED"
  },
  "RequestMessage": {
    "Method": "POST",
    "Uri": "http://localhost/api/Authentication/login",
    "Content": {
      "Headers": {
        "Content-Length": "59",
        "Content-Type": "application/json; charset=utf-8"
      },
      "Value": ""
    }
  }
}

Some of my tests is okay with the simplyfied headers, but this means that i need a way to specify the simplicity of the headers.
So i wondering if it would be possibly to somehow specify how simple the headers should be?

And a side note.. it is pretty hard to use ScrubLinesWithReplace after VerifyHttp.Initialize();.
I havent found a way to scrub the jwt, without ignoring the entire header.

Kind regards

@SimonCropp
Copy link
Member

SimonCropp commented Jan 8, 2025

can you submit a PR with a failing test that shows your desired expected verified file

@Woribe
Copy link
Author

Woribe commented Jan 10, 2025

Hmm.. don't know if that would help.
I might be doing somethin wrong since my headers is so simplified.
I want a result that is more or less like this from your documentation: https://github.com/VerifyTests/Verify.Http?tab=readme-ov-file#resulting-verified-file-1

But they way that i have tried to setup my testsuite i get somthing like this:

{
  "Version": "1.1",
  "Status": "200 OK",
  "Cookies": {
    "jwt": "REDACTED"
  },
  "RequestMessage": {
    "Method": "POST",
    "Uri": "http://localhost/api/Authentication/login",
    "Content": {
      "Headers": {
        "Content-Length": "59",
        "Content-Type": "application/json; charset=utf-8"
      },
      "Value": ""
    }
  }
}

The headers is gone..

Im using a webapplicationfactory to create a httpclient.
And im having a hard time injecting the recording globally as in you documentation: https://github.com/VerifyTests/Verify.Http?tab=readme-ov-file#add-globally
The AddRecordingHttpClient(); method extends on a ServiceCollection instead of a IServiceCollection.

@SimonCropp
Copy link
Member

sorry if you cant distill this down to a minimal repro that illustrates the problem, i dont think i can help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants