@Test
public void testValidateKeyset_noPrimaryKey_shouldFail() throws Exception {

  String keyValue = "01234567890123456";
  // No primary key.
  Keyset invalidKeyset =
      Keyset.newBuilder()
          .addKey(
              Keyset.Key.newBuilder()
                  .setKeyData(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16))
                  .setKeyId(1)
                  .setStatus(KeyStatusType.ENABLED)
                  .setOutputPrefixType(OutputPrefixType.TINK)
                  .build())
          .build();
  try {
    Util.validateKeyset(invalidKeyset);
    fail("Invalid keyset. Expect GeneralSecurityException");
  } catch (GeneralSecurityException e) {
    assertExceptionContains(e, "keyset doesn't contain a valid primary key");
  }
}