Exemplo n.º 1
0
 private void updateAuthority(AuthorityGTS gts) {
   TimeToLive ttl = new TimeToLive();
   ttl.setHours(10);
   ttl.setMinutes(10);
   ttl.setSeconds(10);
   gts.setPerformAuthorization(false);
   gts.setServiceIdentity(null);
   gts.setSyncTrustLevels(false);
   gts.setTimeToLive(ttl);
 }
Exemplo n.º 2
0
 private AuthorityGTS getAuthority(String uri, int priority) {
   TimeToLive ttl = new TimeToLive();
   ttl.setHours(1);
   ttl.setMinutes(1);
   ttl.setSeconds(1);
   AuthorityGTS a1 = new AuthorityGTS();
   a1.setServiceURI(uri);
   a1.setPriority(1);
   a1.setPerformAuthorization(true);
   a1.setServiceIdentity(uri);
   a1.setSyncTrustLevels(true);
   a1.setTimeToLive(ttl);
   return a1;
 }
Exemplo n.º 3
0
  public void testAddInvalidAuthority() {
    GTSAuthorityManager am = new GTSAuthorityManager(GTS_URI, getAuthoritySyncTime(), db);
    try {
      am.clearDatabase();
      TimeToLive ttl = new TimeToLive();
      ttl.setHours(1);
      ttl.setMinutes(1);
      ttl.setSeconds(1);

      // Add Authority no serviceURI
      AuthorityGTS a1 = new AuthorityGTS();
      a1.setPriority(1);
      a1.setPerformAuthorization(true);
      a1.setServiceIdentity("Service");
      a1.setSyncTrustLevels(true);
      a1.setTimeToLive(ttl);
      try {
        am.addAuthority(a1);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Add Authority no ttl
      AuthorityGTS a2 = new AuthorityGTS();
      a2.setServiceURI("Service");
      a2.setPriority(1);
      a2.setPerformAuthorization(true);
      a2.setServiceIdentity("Service");
      a2.setSyncTrustLevels(true);
      try {
        am.addAuthority(a2);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Add Authority no service identity
      AuthorityGTS a3 = new AuthorityGTS();
      a3.setServiceURI("Service");
      a3.setPriority(1);
      a3.setPerformAuthorization(true);
      a3.setSyncTrustLevels(true);
      a3.setTimeToLive(ttl);
      try {
        am.addAuthority(a3);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }
      a3.setServiceIdentity("");
      try {
        am.addAuthority(a3);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      a3.setServiceIdentity("    ");
      try {
        am.addAuthority(a3);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Invalid Priority
      AuthorityGTS a4 = new AuthorityGTS();
      a4.setServiceURI("Service");
      a4.setPriority(0);
      a4.setPerformAuthorization(true);
      a4.setSyncTrustLevels(true);
      a4.setServiceIdentity("Service");
      a4.setTimeToLive(ttl);
      try {
        am.addAuthority(a4);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Invalid Time To Sync
      AuthorityGTS a5 = new AuthorityGTS();
      a5.setServiceURI("Service");
      a5.setPriority(1);
      a5.setPerformAuthorization(true);
      a5.setSyncTrustLevels(true);
      a5.setServiceIdentity("Service");
      TimeToLive ttl2 = new TimeToLive();
      ttl2.setHours(0);
      ttl2.setMinutes(0);
      ttl2.setSeconds(1);
      a5.setTimeToLive(ttl2);
      try {
        am.addAuthority(a5);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      AuthorityGTS a6 = getAuthority("GTS 6", 1);
      am.addAuthority(a6);
      assertTrue(am.doesAuthorityExist(a6.getServiceURI()));
      assertEquals(1, am.getAuthorityCount());
      assertEquals(a6, am.getAuthority(a6.getServiceURI()));

      try {
        am.addAuthority(a6);
        fail("Should not be able to add authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

    } catch (Exception e) {
      FaultUtil.printFault(e);
      assertTrue(false);
    } finally {
      try {
        am.clearDatabase();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 4
0
  public void testUpdateInvalidAuthority() {
    GTSAuthorityManager am = new GTSAuthorityManager(GTS_URI, getAuthoritySyncTime(), db);
    try {
      am.clearDatabase();
      TimeToLive ttl = new TimeToLive();
      ttl.setHours(10);
      ttl.setMinutes(10);
      ttl.setSeconds(10);

      AuthorityGTS a = getAuthority("GTS", 1);
      am.addAuthority(a);
      assertTrue(am.doesAuthorityExist(a.getServiceURI()));
      assertEquals(1, am.getAuthorityCount());
      assertEquals(a, am.getAuthority(a.getServiceURI()));

      // First make sure update works

      a.setTimeToLive(ttl);
      am.updateAuthority(a);

      assertTrue(am.doesAuthorityExist(a.getServiceURI()));
      assertEquals(1, am.getAuthorityCount());
      assertEquals(a, am.getAuthority(a.getServiceURI()));

      // Add Authority no serviceURI
      AuthorityGTS a1 = getAuthority("GTS", 1);
      a1.setServiceURI(null);
      try {
        am.updateAuthority(a1);
        fail("Should not be able to update authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Add Authority no ttl
      AuthorityGTS a2 = getAuthority("GTS", 1);
      a2.setTimeToLive(null);
      try {
        am.addAuthority(a2);
        fail("Should not be able to update authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Add Authority no service identity
      AuthorityGTS a3 = getAuthority("GTS", 1);
      a3.setServiceIdentity(null);
      try {
        am.addAuthority(a3);
        fail("Should not be able to update authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      a3.setServiceIdentity("");
      try {
        am.addAuthority(a3);
        fail("Should not be able to update authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      a3.setServiceIdentity("   ");
      try {
        am.addAuthority(a3);
        fail("Should not be able to update authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Invalid Priority
      AuthorityGTS a4 = getAuthority("GTS", 1);
      a4.setPriority(2);
      try {
        am.addAuthority(a4);
        fail("Should not be able to update authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

      // Adding Self
      AuthorityGTS a5 = getAuthority(GTS_URI, 1);
      a5.setPriority(2);
      try {
        am.addAuthority(a5);
        fail("Should not be able to update authority!!!");
      } catch (IllegalAuthorityFault f) {

      }

    } catch (Exception e) {
      FaultUtil.printFault(e);
      assertTrue(false);
    } finally {
      try {
        am.clearDatabase();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }