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

Test: remove part of the hardcoded network ports #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ivard
Copy link
Member

@ivard ivard commented Jan 31, 2022

The test sometimes fail because one of the hardcoded ports is not available. This PR removes most of these hardcoded ports.

The ones I did not remove where reliant on hardcoded URLs in the test configuration:

  • Revocation server
  • Keyshare server
  • MyIRMA server
  • Test server that hosts the schemes

I did also not remove the global variables for the URL of the requestor server, because the optionReuseServer of the doSession helper relies on a globally specified URL. I managed to make the URL being generated dynamically, but an improvement would still be to refactor doSession such that also the hardcoded requestorServerPort and requestorServerURL can be removed.

Copy link
Member

@sietseringers sietseringers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I have some small questions and remarks.

httpServer := httptest.NewServer(mux)

// Make sure domain is used instead of IP address.
conf.URL = strings.Replace(httpServer.URL, "127.0.0.1", "localhost", 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? If it is because IPv6 might be used, it would be helpful to add that to the comment above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I didn't think of IPv6. The httptest library gives us an IP address instead of a domain. This causes the requestor name test to fail, because this one relies on the domain being localhost. I'm not sure whether we can rewrite that test in such a way that it expects an IP address. If that's not possible, we can use url.Parse to actually replace the host part with localhost. Then it should work in all cases.

Copy link
Member Author

@ivard ivard Feb 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching the domain in the test-requestors scheme to an IP address does not seem to be a very smart solution, because then we hardcode the use of IPv4 even more. I'd say let's do it this way then:

conf.URL = fmt.Sprintf("http://localhost:%d", portFromTestServer(httpServer))

With portFromTestServer being:

func portFromTestServer(s *httptest.Server) int {
	return s.Listener.Addr().(*net.TCPAddr).Port
}

This function can also be used in the function findFreePort to prevent code duplication. The findFreePort function is a bit of a hack for the RequestorServer now. Ideally, that function shouldn't be needed.

internal/sessiontest/helper_servers_test.go Outdated Show resolved Hide resolved
c := redisRequestorConfigDecorator(mr, cert, "", RequestorServerAuthConfiguration)()
c.Configuration.URL = fmt.Sprintf("http://localhost:%d/irma", port)
// Make sure URL of load balancer is being used in QRs.
c.URL = requestorServerURL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the test behaviour itself, instead of just some ports. Strange that it wasn't already like this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it was a mistake in the test I think. We overlooked that one. Luckily, it works like a charm, so it only was a testing mistake and not a functional mistake.

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

Successfully merging this pull request may close these issues.

2 participants