Search in sources :

Example 1 with MockStatusCheckerNoException

use of com.yahoo.athenz.zts.status.MockStatusCheckerNoException in project athenz by yahoo.

the class ZTSImplTest method testGetStatusWithStatusChecker.

@Test
public void testGetStatusWithStatusChecker() {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    Principal principal = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal);
    // if the MockStatusCheckerNoException is set
    // the MockStatusCheckerNoException determines the server is healthy
    System.setProperty(ZTSConsts.ZTS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerNoException.class.getName());
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    ztsImpl.statusPort = 0;
    Status status = ztsImpl.getStatus(context);
    assertEquals(ResourceException.OK, status.getCode());
    // if the MockStatusCheckerThrowException is set
    // the MockStatusCheckerThrowException determines that there is a problem with the server
    System.setProperty(ZTSConsts.ZTS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.NoArguments.class.getName());
    ztsImpl = new ZTSImpl(mockCloudStore, store);
    ztsImpl.statusPort = 0;
    try {
        ztsImpl.getStatus(context);
        fail();
    } catch (ResourceException ex) {
        int code = com.yahoo.athenz.common.server.rest.ResourceException.INTERNAL_SERVER_ERROR;
        String msg = com.yahoo.athenz.common.server.rest.ResourceException.symbolForCode(com.yahoo.athenz.zms.ResourceException.INTERNAL_SERVER_ERROR);
        assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
    }
    System.setProperty(ZTSConsts.ZTS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.NotFound.class.getName());
    ztsImpl = new ZTSImpl(mockCloudStore, store);
    ztsImpl.statusPort = 0;
    try {
        ztsImpl.getStatus(context);
        fail();
    } catch (ResourceException ex) {
        int code = com.yahoo.athenz.common.server.rest.ResourceException.NOT_FOUND;
        String msg = com.yahoo.athenz.common.server.rest.ResourceException.symbolForCode(com.yahoo.athenz.zms.ResourceException.NOT_FOUND);
        assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
    }
    System.setProperty(ZTSConsts.ZTS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.InternalServerErrorWithMessage.class.getName());
    ztsImpl = new ZTSImpl(mockCloudStore, store);
    ztsImpl.statusPort = 0;
    try {
        ztsImpl.getStatus(context);
        fail();
    } catch (ResourceException ex) {
        int code = com.yahoo.athenz.common.server.rest.ResourceException.INTERNAL_SERVER_ERROR;
        String msg = "error message";
        assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
    }
    System.setProperty(ZTSConsts.ZTS_PROP_STATUS_CHECKER_FACTORY_CLASS, MockStatusCheckerThrowException.CauseRuntimeException.class.getName());
    ztsImpl = new ZTSImpl(mockCloudStore, store);
    ztsImpl.statusPort = 0;
    try {
        ztsImpl.getStatus(context);
        fail();
    } catch (ResourceException ex) {
        int code = com.yahoo.athenz.common.server.rest.ResourceException.INTERNAL_SERVER_ERROR;
        String msg = "runtime exception";
        assertEquals(new ResourceError().code(code).message(msg).toString(), ex.getData().toString());
    }
    System.clearProperty(ZTSConsts.ZTS_PROP_STATUS_CHECKER_FACTORY_CLASS);
}
Also used : AccessStatus(com.yahoo.athenz.zts.ZTSAuthorizer.AccessStatus) ServiceX509RefreshRequestStatus(com.yahoo.athenz.zts.ZTSImpl.ServiceX509RefreshRequestStatus) MockStatusCheckerNoException(com.yahoo.athenz.zts.status.MockStatusCheckerNoException) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Aggregations

Principal (com.yahoo.athenz.auth.Principal)1 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)1 ZMSFileChangeLogStore (com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore)1 AccessStatus (com.yahoo.athenz.zts.ZTSAuthorizer.AccessStatus)1 ServiceX509RefreshRequestStatus (com.yahoo.athenz.zts.ZTSImpl.ServiceX509RefreshRequestStatus)1 MockStatusCheckerNoException (com.yahoo.athenz.zts.status.MockStatusCheckerNoException)1 DataStore (com.yahoo.athenz.zts.store.DataStore)1 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore)1 Test (org.testng.annotations.Test)1