TicketSeedFileParser { public List<SessionTicketKey> parse(File file) throws IOException { return parseBytes(Files.toByteArray(file)); } TicketSeedFileParser();  TicketSeedFileParser(String hexSalt);  TicketSeedFileParser(byte[] salt); List<SessionTicketKey> parse(File file); List<SessionTicketKey> parseBytes(byte[] json);  }
@Test public void testParseSeeds() throws IOException { List<SessionTicketKey> keys = new TicketSeedFileParser().parse( new File(TicketSeedFileParserTest.class.getResource("/good_seeds.json").getFile())); Assert.assertEquals(6, keys.size()); for (int i = 0; i < keys.size() / 2; i += 2) { Assert.assertEquals(keys.get(i).getHmacKey(), keys.get(i + 2).getHmacKey(), "HMAC keys not equal"); Assert.assertEquals(keys.get(i).getName(), keys.get(i + 2).getName(), "key names not equal"); Assert.assertEquals(keys.get(i).getAesKey(), keys.get(i + 2).getAesKey(), "AES keys not equal"); } for (int i = 0; i < keys.size() - 1; i++) { Assert.assertNotEquals(keys.get(i).getHmacKey(), keys.get(i + 1).getHmacKey()); Assert.assertNotEquals(keys.get(i).getName(), keys.get(i + 1).getName()); Assert.assertNotEquals(keys.get(i).getAesKey(), keys.get(i + 1).getAesKey()); } List<SessionTicketKey> keys2 = new TicketSeedFileParser().parse( new File(TicketSeedFileParserTest.class.getResource("/good_seeds.json").getFile())); Assert.assertEquals(keys.size(), keys2.size()); for (int i = 0; i < keys.size(); ++i) { Assert.assertEquals(keys.get(i).getAesKey(), keys2.get(i).getAesKey(), "AES keys not equal"); Assert.assertEquals(keys.get(i).getName(), keys2.get(i).getName(), "key names not equal"); Assert.assertEquals(keys.get(i).getHmacKey(), keys2.get(i).getHmacKey(), "HMAC keys not equal"); } }
@Test public void testParseCurrentSeeds() throws IOException { List<SessionTicketKey> keys = new TicketSeedFileParser().parse( new File(TicketSeedFileParserTest.class.getResource("/seeds_with_only_current.json").getFile())); Assert.assertEquals(2, keys.size()); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "current seeds must not be empty") public void testParseNoCurrentSeeds() throws IOException { new TicketSeedFileParser().parse( new File(TicketSeedFileParserTest.class.getResource("/seeds_with_no_current.json").getFile())); }
@Test(expectedExceptions = JsonParseException.class) public void testParseBadJson() throws IOException { new TicketSeedFileParser().parse( new File(TicketSeedFileParserTest.class.getResource("/seeds_bad_json.json").getFile())); }