@Test
  public void testPortReleaseOnInvalidConfig() throws Exception {
    // no IDP setup here; start HS2 in non-SAML mode
    miniHS2.start(new HashMap<>());
    int samlResponsePort = MetaStoreTestUtils.findFreePort();
    try (TestHiveConnection connection = new TestHiveConnection(
        getSamlJdbcConnectionUrl(30, samlResponsePort), new Properties(), USER1,
        USER1_PASSWORD)) {
      fail("Connection should not have succeeded since HS2 is not configured correctly");
    } catch (Exception e) {
      assertTrue("Port must be released after SSO flow",
          isPortAvailable(samlResponsePort));
    }
  }
Here we start HS2 without SAML mode and attempt to use browser SSO against it.
Test makes sure that connection fails and port is released.
itests/hive-unit/src/test/java/org/apache/hive/service/auth/saml/TestHttpSamlAuthentication.java