@Test(expectedExceptions = NtlmEngineException.class) public void testGenerateType3MsgThrowsExceptionWhenChallengeTooShort() { NtlmEngine engine = new NtlmEngine(); engine.generateType3Msg("username", "password", "localhost", "workstation", Base64.getEncoder().encodeToString("a".getBytes())); fail("An NtlmEngineException must have occurred as challenge length is too short"); }
@Test(expectedExceptions = NtlmEngineException.class) public void testGenerateType3MsgThrowsExceptionWhenChallengeDoesNotFollowCorrectFormat() { NtlmEngine engine = new NtlmEngine(); engine.generateType3Msg("username", "password", "localhost", "workstation", Base64.getEncoder().encodeToString("challenge".getBytes())); fail("An NtlmEngineException must have occurred as challenge format is not correct"); }
@Test public void testGenerateType1Msg() { NtlmEngine engine = new NtlmEngine(); String message = engine.generateType1Msg(); assertEquals(message, "TlRMTVNTUAABAAAAAYIIogAAAAAoAAAAAAAAACgAAAAFASgKAAAADw==", "Incorrect type1 message generated"); }
@Test(expectedExceptions = NtlmEngineException.class) public void testGenerateType3MsgThworsExceptionWhenType2IndicatorNotPresent() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); buf.write("NTLMSSP".getBytes(StandardCharsets.US_ASCII)); buf.write(0); // type 2 indicator buf.write(3); buf.write(0); buf.write(0); buf.write(0); buf.write("challenge".getBytes()); NtlmEngine engine = new NtlmEngine(); engine.generateType3Msg("username", "password", "localhost", "workstation", Base64.getEncoder().encodeToString(buf.toByteArray())); buf.close(); fail("An NtlmEngineException must have occurred as type 2 indicator is incorrect"); }
@Test(expectedExceptions = NtlmEngineException.class) public void testGenerateType3MsgThrowsExceptionWhenUnicodeSupportNotIndicated() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); buf.write("NTLMSSP".getBytes(StandardCharsets.US_ASCII)); buf.write(0); // type 2 indicator buf.write(2); buf.write(0); buf.write(0); buf.write(0); buf.write(longToBytes(1L)); // we want to write a Long // flags buf.write(0);// unicode support indicator buf.write(0); buf.write(0); buf.write(0); buf.write(longToBytes(1L));// challenge NtlmEngine engine = new NtlmEngine(); engine.generateType3Msg("username", "password", "localhost", "workstation", Base64.getEncoder().encodeToString(buf.toByteArray())); buf.close(); fail("An NtlmEngineException must have occurred as unicode support is not indicated"); }
@Test public void testGenerateType3Msg() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); buf.write("NTLMSSP".getBytes(StandardCharsets.US_ASCII)); buf.write(0); // type 2 indicator buf.write(2); buf.write(0); buf.write(0); buf.write(0); buf.write(longToBytes(0L)); // we want to write a Long // flags buf.write(1);// unicode support indicator buf.write(0); buf.write(0); buf.write(0); buf.write(longToBytes(1L));// challenge NtlmEngine engine = new NtlmEngine(); String type3Msg = engine.generateType3Msg("username", "password", "localhost", "workstation", Base64.getEncoder().encodeToString(buf.toByteArray())); buf.close(); assertEquals( type3Msg, "TlRMTVNTUAADAAAAGAAYAEgAAAAYABgAYAAAABIAEgB4AAAAEAAQAIoAAAAWABYAmgAAAAAAAACwAAAAAQAAAgUBKAoAAAAP1g6lqqN1HZ0wSSxeQ5riQkyh7/UexwVlCPQm0SHU2vsDQm2wM6NbT2zPonPzLJL0TABPAEMAQQBMAEgATwBTAFQAdQBzAGUAcgBuAGEAbQBlAFcATwBSAEsAUwBUAEEAVABJAE8ATgA=", "Incorrect type3 message generated"); }