KnoxSSOAuthenticationFilter implements Filter { protected String getKnoxKey() throws IOException { String knoxKey; if ((this.knoxKeyString == null || this.knoxKeyString.isEmpty()) && this.knoxKeyFile != null) { List<String> keyLines = Files.readAllLines(knoxKeyFile, StandardCharsets.UTF_8); knoxKey = String.join("", keyLines); } else { knoxKey = this.knoxKeyString; } return knoxKey; } KnoxSSOAuthenticationFilter(String userSearchBase,
                                     Path knoxKeyFile,
                                     String knoxKeyString,
                                     String knoxCookie,
                                     LdapTemplate ldapTemplate); @Override void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain);  }
@Test public void getKnoxKeyShouldProperlyReturnKnoxKey() throws Exception { { KnoxSSOAuthenticationFilter knoxSSOAuthenticationFilter = spy(new KnoxSSOAuthenticationFilter("userSearchBase", mock(Path.class), "knoxKeyString", "knoxCookie", mock(LdapTemplate.class) )); assertEquals("knoxKeyString", knoxSSOAuthenticationFilter.getKnoxKey()); } { FileUtils.writeStringToFile(new File("./target/knoxKeyFile"), "knoxKeyFileKeyString", StandardCharsets.UTF_8); KnoxSSOAuthenticationFilter knoxSSOAuthenticationFilter = spy(new KnoxSSOAuthenticationFilter("userSearchBase", Paths.get("./target/knoxKeyFile"), null, "knoxCookie", mock(LdapTemplate.class) )); assertEquals("knoxKeyFileKeyString", knoxSSOAuthenticationFilter.getKnoxKey()); } }