public void testSeen() {
    String nonce = _dateFormat.format(new Date()) + "abc";

    assertEquals(NonceVerifier.OK, _nonceVerifier.seen("op1", nonce));
    assertEquals(NonceVerifier.SEEN, _nonceVerifier.seen("op1", nonce));

    assertEquals(NonceVerifier.OK, _nonceVerifier.seen("op2", nonce));
  }
  public void testNonceCleanup() throws Exception {
    NonceGenerator nonceGenerator = new IncrementalNonceGenerator();
    _nonceVerifier = createVerifier(1);

    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.com", nonceGenerator.next()));
    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.com", nonceGenerator.next()));
    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.com", nonceGenerator.next()));
    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.com", nonceGenerator.next()));

    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.net", nonceGenerator.next()));
    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.net", nonceGenerator.next()));
    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.net", nonceGenerator.next()));
    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.net", nonceGenerator.next()));

    Thread.sleep(1000);

    assertEquals(
        NonceVerifier.OK, _nonceVerifier.seen("http://example.org", nonceGenerator.next()));
  }
  public void testExpired() {
    Date now = new Date();
    Date past = new Date(now.getTime() - 1000L * (MAX_AGE + 1));

    String nonce = _dateFormat.format(past) + "abc";

    assertEquals(NonceVerifier.TOO_OLD, _nonceVerifier.seen("op1", nonce));
  }
 public void testMalformed() {
   assertEquals(NonceVerifier.INVALID_TIMESTAMP, _nonceVerifier.seen("op1", "xyz"));
 }