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

Endpoint details set in RequestSpecification aren't properly applied to endpoint #22

Closed
bheemreddy181 opened this issue Nov 10, 2022 · 45 comments
Assignees
Labels
bug Something isn't working

Comments

@bheemreddy181
Copy link

Currently, we support C# class objects for reading the Input API request , we might not need C# class objects all the time rather than creating a raw JSON for such cases can we support dictionary objects ?

@basdijkstra basdijkstra added the question Further information is requested label Nov 10, 2022
@basdijkstra
Copy link
Owner

Json.NET has got you covered on that already. I've added an example to make this more clear, and I will add that to the docs as well:

public void DictionaryCanBeSerializedToJson()

Does that answer your question? If so please close this issue, if not, please elaborate.

@basdijkstra
Copy link
Owner

Even better, it works with anonymous types, too, no need to even create a Dictionary:

public void AnonymousObjectCanBeSerializedToJson()

@bheemreddy181
Copy link
Author

Interesting, I was getting the below error with a dictionary

System.AggregateException : One or more errors occurred. (The 'file' scheme is not supported.)
  ----> System.NotSupportedException : The 'file' scheme is not supported.
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at RestAssuredNet.RA.ExecutableRequest.Send(HttpMethod httpMethod, String endpoint)
   at RestAssuredNet.RA.ExecutableRequest.Post(String endpoint)
   at IntegrationTests.Tests.CreateLeadTests.CreateLeadTest() in /Users/bheemvennapureddy/SummitApi/IntegrationTests/Tests/CreateLeadTests.cs:line 33
--NotSupportedException
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at RestAssuredNet.RA.Internal.HttpRequestProcessor.Send(HttpRequestMessage request, CookieCollection cookieCollection)

@basdijkstra
Copy link
Owner

Can you add the test that you used?

@bheemreddy181
Copy link
Author

Let me debug this a bit more and provide a detailed info on this.

@bheemreddy181
Copy link
Author

bheemreddy181 commented Nov 10, 2022

I assume the endpoint is not getting set correctly from request Specification.
Screen Shot 2022-11-10 at 11 49 34 AM
Screen Shot 2022-11-10 at 11 56 13 AM

Screen Shot 2022-11-10 at 11 58 38 AM

Screen Shot 2022-11-10 at 11 58 47 AM

@basdijkstra
Copy link
Owner

basdijkstra commented Nov 10, 2022

Thanks.

Do you have a GitHub link somewhere where I can find the test? If not I’ll rebuild it myself but I might end up not having the exact same situation.

Can you see in your debug session what the complete endpoint is that RestAssured is trying to invoke?

And finally, did you run this against the public 1.0.0 version or did you package the library yourself?

@basdijkstra
Copy link
Owner

Hmm..

When I use the same setup like this with v1.0.0:

private RequestSpecification requestSpec;

        [SetUp]
        public void CreateRequestSpecification()
        {
            requestSpec = new RequestSpecBuilder()
                .WithScheme("http")
                .WithHostName("api.zippopotam.us")
                .WithBasePath("us")
                .Build();
        }

        [Test]
        public void CheckResponseStatusCodeAndJsonResponseBodyElementValue()
        {
            Given()
                .Spec(requestSpec)
                .When()
                .Get("/90210")
                .Then()
                .Body("$.places[0].state", NHamcrest.Is.EqualTo("California"));
        }

It works as expected. Again, can you please tell me what the endpoint is that RestAssured is trying to hit?

@bheemreddy181
Copy link
Author

looks like i am using the formatUrlEnocoded branch not that master ( 1.0.0 ) - Can you try on that branch ?

@basdijkstra
Copy link
Owner

No, because that doesn't exist anymore. Can we leave this open until the next release? That should not take me more than a couple of days now, and since I've done quite a bit of work on the RequestSpecification, things might have changed for the better for you :)

@bheemreddy181
Copy link
Author

Sure that works

@bheemreddy181
Copy link
Author

Screen Shot 2022-11-10 at 1 09 50 PM

@basdijkstra
Copy link
Owner

Yes, but the actual endpoint is only constructed inside the Send() method, that's where the RequestSpecification is applied.

See here:

this.request = RequestSpecificationProcessor.Apply(this.requestSpecification, this.request, endpoint);

Can you debug into that? Or use Fiddler or WireShark to see what the outgoing traffic is, that's the actual endpoint.

@bheemreddy181
Copy link
Author

this is what i see
Screen Shot 2022-11-10 at 1 18 38 PM

@basdijkstra
Copy link
Owner

basdijkstra commented Nov 10, 2022

Thanks, that's what I was looking for. That's definitely not good.

Once again, let's park this until the next proper release. If it's still there, I'll try and fix that ASAP but I probably need you to publish this on GitHub (or send it to me via email: [email protected]) so I can reproduce it.

Even better would be to do that before the next release, so I can make sure it works and I don't ship something with a bug. Would that be possible?

@basdijkstra basdijkstra changed the title [Feature-Request] Support Dictionary Object for Request Body Endpoint details set in RequestSpecification aren't properly applied to endpoint Nov 10, 2022
@bheemreddy181
Copy link
Author

Sure i can create an example on Github

@bheemreddy181
Copy link
Author

@basdijkstra
Copy link
Owner

Thanks. The error I'm getting when running your test with version 1.0.0 is slightly different:

System.AggregateException : One or more errors occurred. (The SSL connection could not be established, see inner exception.) ----> RestAssuredNet.RA.Exceptions.HttpRequestProcessorException : The SSL connection could not be established, see inner exception.

I've seen that with other HTTPS calls, too, and I'll address it in #13. Thank you for uploading that example!

Again, let's keep this open until version 1.1.0 is released and test again.

@basdijkstra basdijkstra added bug Something isn't working and removed question Further information is requested labels Nov 11, 2022
@bheemreddy181
Copy link
Author

Sounds good thanks

@basdijkstra
Copy link
Owner

basdijkstra commented Nov 11, 2022

OK, I've found the problem (and another one in the logging, too). The problem is that the RequestSpecification port defaults to 80, which is not a useful value when you use https (it should be 443 in that case). When you change the port to 443, it works (or well, you get an HTTP 401 Unauthorized because your token value is invalid) as well as a NullReferenceException because there is no body to log and you call Log().All().

image

I've also tested it by adding .WithPort(443) to the RequestSpecification and that yields the same result, so the values from the RequestSpecification are applied to the request as expected, it seems.

I'll create separate issues for those, is it OK to close this one then, @bheemreddy181?

@bheemreddy181
Copy link
Author

Gotcha - Sounds good to me wasn't that defaulting to port 80 before too ?

@basdijkstra
Copy link
Owner

Gotcha - Sounds good to me wasn't that defaulting to port 80 before too ?

Yes and it still does, because that's the default port for HTTP, but not for HTTPS. I might be better off not setting a default at all..

@basdijkstra
Copy link
Owner

Anyway, closing this one, we can always continue the conversation in the other issue.

@bheemreddy181
Copy link
Author

is that ok to keep this request open until things get cleared on my side ?

@bheemreddy181
Copy link
Author

Looks like you are framing the actual endpoint when the URI builder throws an exception, in my case I don't see an exception is being thrown here
Screen Shot 2022-11-13 at 3 20 52 PM

@basdijkstra
Copy link
Owner

basdijkstra commented Nov 14, 2022

Yeah, happy to keep this open. It's really weird, though, because the UriFormatException should be thrown here according to the Microsoft docs (which are typically very accurate):

image
(from https://learn.microsoft.com/en-us/dotnet/api/system.uri.-ctor?view=net-7.0#system-uri-ctor(system-string))

The last sentence is key here. What you're passing in is a relative Uri, and that should throw the UriFormatException leading to the actual Uri being built from the RequestSpecification.

@basdijkstra basdijkstra reopened this Nov 14, 2022
@basdijkstra basdijkstra added the waiting for feedback Waiting for feedback from issue submitter label Nov 14, 2022
@bheemreddy181
Copy link
Author

I think this is the issue dotnet/runtime#27813

@bheemreddy181
Copy link
Author

I think you might need to do something of this sort
Uri uri = new Uri(url); try { string host = uri.Host; } catch (UriFormatException) { Console.WriteLine("Bad url: {0}", url); }

@basdijkstra
Copy link
Owner

That explains a lot of things... So, what .NET version are you using (the issue talks about .NET Core 2.1) and what operating system are you on? Just for my information :) I will need to find a way to fix / work around this.

@basdijkstra basdijkstra removed the waiting for feedback Waiting for feedback from issue submitter label Nov 14, 2022
@bheemreddy181
Copy link
Author

I am on dotnet 6 and Operating system Mac OS.

@basdijkstra
Copy link
Owner

basdijkstra commented Nov 14, 2022

Thanks! It was only time before I'd run into cross-OS compatibility issues, I guess.. I'll have a look and see how to best fix this. I'll take your suggestion into account.

@bheemreddy181
Copy link
Author

Sounds good thanks.

@basdijkstra basdijkstra added in progress This issue is currently being worked on waiting for feedback Waiting for feedback from issue submitter and removed in progress This issue is currently being worked on labels Nov 15, 2022
@basdijkstra
Copy link
Owner

Hey @bheemreddy181, I think I've fixed this now. Could you please retest with RestAssured.Net version 1.2.0-alpha, which is available as a prerelease through NuGet?

@bheemreddy181
Copy link
Author

Sure will test sometime today.

@bheemreddy181
Copy link
Author

Yes that worked. .RelaxedHttpsValidation() is what I am a bit confused on, why do I need to add that all the time for all requests. (Probably a different issue we can talk on)

@basdijkstra
Copy link
Owner

Thank you for verifying and happy to see that it works. The RelaxedHttpsValidation disables SSL checks, meaning that there’s no verification on whether or not there’s a valid certificate for the HTTPS connection. It’s an easy way to skip having to configure certificates for the connection if that’s not the point of the test.

@basdijkstra basdijkstra removed the waiting for feedback Waiting for feedback from issue submitter label Nov 15, 2022
@bheemreddy181
Copy link
Author

I understand that token generation worked with RelaxedHttpsValidation before and all of a sudden this is a required in the implementation did something change around that ?

@basdijkstra
Copy link
Owner

Hey @bheemreddy181, token generation and SSL checks are two entirely different things. One has to do with user authorization, the other with network-level connection security.

If you think something's wrong here, please submit a new issue. No point in continuing a discussion in a closed issue.

@bheemreddy181
Copy link
Author

Thanks for the explanation.Ya will do.

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