How to validate request headers and cookies #335

Closed
opened 2025-12-29 15:21:10 +01:00 by adam · 3 comments
Owner

Originally created by @genesispvtltd on GitHub (Feb 11, 2021).

Hi , I just want to know how can I show unauthorized when the cookie is not passed in the request. I wrote the stub like below but it did not work.pls help to correct it thanks

wireMockServer                 
            .Given(
         Request.Create().WithPath("/PayrollReportService/v1/clients/208944/payrollreports*")  
         .UsingGet()
         .WithCookie("pay",  "*", MatchBehaviour.RejectOnMatch)   
         ).AtPriority(1)
         .RespondWith(
           Response.Create()
            .WithProxy(proxyUrl)
            .WithStatusCode(HttpStatusCode.Unauthorized)
         );

Also second question is if someone passed wrong cookie say like the cookie name is pay but someone passed cookie name as paid and that time I want to display unauthorized how can i code that stub thanks.

Originally created by @genesispvtltd on GitHub (Feb 11, 2021). Hi , I just want to know how can I show unauthorized when the cookie is not passed in the request. I wrote the stub like below but it did not work.pls help to correct it thanks ``` c# wireMockServer .Given( Request.Create().WithPath("/PayrollReportService/v1/clients/208944/payrollreports*") .UsingGet() .WithCookie("pay", "*", MatchBehaviour.RejectOnMatch) ).AtPriority(1) .RespondWith( Response.Create() .WithProxy(proxyUrl) .WithStatusCode(HttpStatusCode.Unauthorized) ); ``` Also second question is if someone passed wrong cookie say like the cookie name is pay but someone passed cookie name as paid and that time I want to display unauthorized how can i code that stub thanks.
adam added the question label 2025-12-29 15:21:10 +01:00
adam closed this issue 2025-12-29 15:21:11 +01:00
Author
Owner

@genesispvtltd commented on GitHub (Feb 15, 2021):

Hello, is there a way we can do this thanks.

@genesispvtltd commented on GitHub (Feb 15, 2021): Hello, is there a way we can do this thanks.
Author
Owner

@StefH commented on GitHub (Feb 15, 2021):

The easiest would be to:

1]

Add a mapping which uses path "/PayrollReportService/v1/clients/208944/payrollreports*", checks the valid cookie and returns http 200.

2]

Add another mapping which uses the same path, but has no check on the cookie and returns Unauthorized

@StefH commented on GitHub (Feb 15, 2021): The easiest would be to: ### 1] Add a mapping which uses path `"/PayrollReportService/v1/clients/208944/payrollreports*"`, checks the valid cookie and returns http 200. ### 2] Add another mapping which uses the same path, but has no check on the cookie and returns Unauthorized
Author
Owner

@genesispvtltd commented on GitHub (Feb 16, 2021):

Thanks this worked

@genesispvtltd commented on GitHub (Feb 16, 2021): Thanks this worked
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#335