Esempio 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();
  }
Esempio 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);
  }
Esempio n. 3
0
  public TestResult validate(License license, ValidationParameters validationParameters) {
    Date currentDate = validationParameters.getValidationDate();

    boolean passed = true;
    // Check that the currentDate > startDate
    if (currentDate.before(license.getStartDate())) {
      logger.fine("Current date is before the license start date");
      passed = false;
    }

    return new TestResult(LicenseTest.PRIOR, passed);
  }
Esempio n. 4
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);
  }