Skip to content

Instantly share code, notes, and snippets.

@gaborgsomogyi
Created May 19, 2021 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaborgsomogyi/8092c9be8ac65b62baa00ccf3f344e67 to your computer and use it in GitHub Desktop.
Save gaborgsomogyi/8092c9be8ac65b62baa00ccf3f344e67 to your computer and use it in GitHub Desktop.

sun.net.www.protocol.http.NegotiateAuthentication caches per host (and no port information in the key) whether negotiation is supported or not (for instance SPNEGO). Worth to mention the cache is static (god knows why). This is so far so good but can lead to issues in unit tests. For example:

  • Developer writes a positive and negative test case for an SPNEGO protected server
  • Normally the order of test cases are not defined
  • Negative test case executes where SPNEGO turned off and expect 401
  • NegotiateAuthentication stores false in a map
  • Negative test case pass
  • Positive test case executes where SPNEGO turned on and expect 200
  • NegotiateAuthentication gives base isSupported=false from cache
  • Positive test case fails

To overcome this issue it would be good to have a configuration in the JVM not to cache such things but it's not available. All the rest is just hacking it around. For example:

  • Defining explicit order of tests (which is super ugly and brittle)
  • Map localhost to a different host name (not sure it's possible w/o horrible hacks)
  • ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment