Exemplo n.º 1
0
  /** Test of validate method, of class Validator. */
  public void testValidate() throws Exception {
    System.out.println("validate - Simple");

    KeyPair pair = KeyManager.createKeyPair();
    License license = LicenseFactory.createLicense();
    license.addProperty("Name", "Jason Nichols");
    license.addProperty("Email", "*****@*****.**");
    license.addProperty("Gibberish", "qwertyasdfg");

    LicenseSigner signer = LicenseSigner.createLicenseSigner((DSAPrivateKey) pair.getPrivate());
    signer.sign(license);

    String key = new String(Hex.encodeHex(pair.getPublic().getEncoded()));
    Validator validator = new Validator(license, key);
    validator.validate();
  }
Exemplo n.º 2
0
  public void testExpired() throws Exception {
    System.out.println("validate - Expired");

    KeyPair pair = KeyManager.createKeyPair();
    License license = LicenseFactory.createLicense();
    license.setStartDate(new Date(100));
    LicenseSigner signer = LicenseSigner.createLicenseSigner((DSAPrivateKey) pair.getPrivate());
    signer.sign(license);

    String key = new String(Hex.encodeHex(pair.getPublic().getEncoded()));
    Validator validator = new Validator(license, key);
    boolean ex = false;
    try {
      validator.validate();
    } catch (ValidatorException e) {
      System.out.println("\t" + e.getMessage());
      ex = true;
    }
    assertTrue(ex);
  }
Exemplo n.º 3
0
  public void testBlacklist() throws Exception {
    System.out.println("validate - Blacklist");

    KeyPair pair = KeyManager.createKeyPair();
    License license = LicenseFactory.createLicense();
    license.addProperty("Name", "Jason Nichols");
    license.addProperty("Email", "*****@*****.**");
    license.addProperty("Gibberish", "qwertyasdfg");

    LicenseSigner signer = LicenseSigner.createLicenseSigner((DSAPrivateKey) pair.getPrivate());
    signer.sign(license);

    String key = new String(Hex.encodeHex(pair.getPublic().getEncoded()));
    Validator validator = new Validator(license, key);
    validator.addBlacklistedLicense(license.getLicenseSignatureString());
    boolean ex = false;
    try {
      validator.validate();
    } catch (ValidatorException e) {
      System.out.println("\t" + e.getMessage());
      ex = true;
    }
    assertTrue(ex);
  }