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

Encoded RequestURI when using QueryParam and RequestSpecBuilder #47

Closed
MuresanCristianRichard opened this issue Jan 4, 2023 · 8 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@MuresanCristianRichard
Copy link

MuresanCristianRichard commented Jan 4, 2023

Hi Bas,

I noticed an issue when I try to construct the RequestURI using RequestSpecBuilder and QueryParam.
Given the following example:

        requestSpecification = new RequestSpecBuilder()
            .WithScheme("https")
            .WithHostName("somehost.net")
            .WithBasePath("api")
            .WithOAuth2(token)
            .WithRelaxedHttpsValidation()
            .Build();
   [Test]
    public void SingleQueryParameterCanBeSpecified()
    {
       Given()
        .Spec(requestSpecification)
        .QueryParam("name", "john")
        .When()
        .Get("/check-something")
        .Then()
        .StatusCode(200);
        .Extract()
        .Response();
    }

The result is a 404 and by debugging we got:
{Method: GET, RequestUri: 'https://somehost.net/api/check-something%3Fname=john'
->encoded

By changing the test method to this:

    [Test]
    public void SingleQueryParameterCanBeSpecified()
    {
       Given()
        .Spec(requestSpecification)
        .QueryParam("name", "john")
        .When()
        .Get("https://somehost.net/api/check-something")
        .Then()
        .StatusCode(200);
        .Extract()
        .Response();
    }

that means we send the whole path for RequestURI we got the following result:
statusCode 200 and
Method: GET, RequestUri: 'https://somehost.net/api/check-something?name=john'

The encoding value from "?" to "%3F" makes the request to fail.
There is a method in Java RestAssured called:
.urlEncodingEnabled(false)

example:
RequestSpecification mySpec = new RequestSpecBuilder().setUrlEncodingEnabled(false)

Is there a way to fix this in my code or is this a Defect in library that can be released soon?
Thanks!

@basdijkstra
Copy link
Owner

That definitely looks like a defect :)

Thank you for reporting, I’ll have a look over / after the weekend.

@basdijkstra basdijkstra self-assigned this Jan 4, 2023
@basdijkstra basdijkstra added bug Something isn't working good first issue Good for newcomers labels Jan 4, 2023
@MuresanCristianRichard
Copy link
Author

Thanks for considering this defect.

Have a great day,
Cristian.

@basdijkstra
Copy link
Owner

I can reproduce the issue and I've located the part of the code where the problem occurs. Shouldn't take me too long to fix this.

@basdijkstra basdijkstra added the in progress This issue is currently being worked on label Jan 7, 2023
@MuresanCristianRichard
Copy link
Author

Sounds amazing. Thanks again!

@basdijkstra
Copy link
Owner

basdijkstra commented Jan 10, 2023

Hey @MuresanCristianRichard, I think I fixed this just now. Could you please have a look at this commit?

584208b

And specifically whether this test represents your situation correctly:

public void QueryParametersAreAddedToRelativePathCorrectly()

If so, I'll release a new version ASAP.

@basdijkstra basdijkstra added waiting for feedback Waiting for feedback from issue submitter and removed in progress This issue is currently being worked on labels Jan 10, 2023
@MuresanCristianRichard
Copy link
Author

Hi @basdijkstra .
This test that you linked express exactly my situation. Looks good to me!

Have a great day!

@basdijkstra
Copy link
Owner

basdijkstra commented Jan 10, 2023

Hey @MuresanCristianRichard, new version available now: https://www.nuget.org/packages/RestAssured.Net/2.2.1

Could you please update to this version and see if it properly resolves your issue? If so, can I ask you to close the issue?

@MuresanCristianRichard
Copy link
Author

Looks good in our tests too. We implemented a short workaround but I just delete it and It works properly now.
Thanks again for your quick fix. It helps a lot!

Have a great day!

@basdijkstra basdijkstra removed the waiting for feedback Waiting for feedback from issue submitter label Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants