Search in sources :

Example 1 with DockstoreWebserviceConfiguration

use of io.dockstore.webservice.DockstoreWebserviceConfiguration in project dockstore by dockstore.

the class PublicStateManagerIT method setupManager.

@BeforeClass
public static void setupManager() {
    DockstoreWebserviceConfiguration config = new DockstoreWebserviceConfiguration();
    config.getEsConfiguration().setHostname("localhost");
    config.getEsConfiguration().setPort(9200);
    PublicStateManagerIT.manager = PublicStateManager.getInstance();
    manager.setConfig(config);
}
Also used : DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) BeforeClass(org.junit.BeforeClass)

Example 2 with DockstoreWebserviceConfiguration

use of io.dockstore.webservice.DockstoreWebserviceConfiguration in project dockstore by dockstore.

the class SamPermissionsImplTest method setup.

@Before
public void setup() {
    ownerPolicy = new AccessPolicyResponseEntry();
    ownerPolicy.setPolicyName(SamConstants.OWNER_POLICY);
    AccessPolicyMembership accessPolicyMembership = new AccessPolicyMembership();
    accessPolicyMembership.setRoles(Collections.singletonList(SamConstants.OWNER_POLICY));
    accessPolicyMembership.setMemberEmails(Collections.singletonList("jdoe@ucsc.edu"));
    ownerPolicy.setPolicy(accessPolicyMembership);
    writerPolicy = new AccessPolicyResponseEntry();
    writerPolicy.setPolicyName(SamConstants.WRITE_POLICY);
    AccessPolicyMembership writerMembership = new AccessPolicyMembership();
    writerMembership.setRoles(Collections.singletonList(SamConstants.WRITE_POLICY));
    writerMembership.setMemberEmails(Collections.singletonList(JANE_DOE_GMAIL_COM));
    writerPolicy.setPolicy(writerMembership);
    AccessPolicyResponseEntry readerPolicy = new AccessPolicyResponseEntry();
    readerPolicy.setPolicyName(SamConstants.READ_POLICY);
    AccessPolicyMembership readerMembership = new AccessPolicyMembership();
    readerMembership.setRoles(Collections.singletonList(SamConstants.READ_POLICY));
    readerMembership.setMemberEmails(Collections.singletonList(JANE_DOE_GMAIL_COM));
    readerPolicy.setPolicy(readerMembership);
    TokenDAO tokenDAO = Mockito.mock(TokenDAO.class);
    DockstoreWebserviceConfiguration configMock = Mockito.mock(DockstoreWebserviceConfiguration.class);
    when(configMock.getSamConfiguration()).thenReturn(new DockstoreWebserviceConfiguration.SamConfiguration());
    samPermissionsImpl = Mockito.spy(new SamPermissionsImpl(tokenDAO, configMock));
    doReturn(Optional.of("my token")).when(samPermissionsImpl).googleAccessToken(userMock);
    doReturn(Mockito.mock(Token.class)).when(samPermissionsImpl).googleToken(userMock);
    resourcesApiMock = Mockito.mock(ResourcesApi.class);
    ApiClient apiClient = Mockito.mock(ApiClient.class);
    when(apiClient.escapeString(ArgumentMatchers.anyString())).thenAnswer(invocation -> invocation.getArgument(0));
    when(resourcesApiMock.getApiClient()).thenReturn(apiClient);
    when(samPermissionsImpl.getResourcesApi(userMock)).thenReturn(resourcesApiMock);
    workflowInstance = Mockito.mock(Workflow.class);
    when(workflowInstance.getWorkflowPath()).thenReturn("foo");
    ownerPermission = new Permission();
    ownerPermission.setEmail("jdoe@ucsc.edu");
    ownerPermission.setRole(Role.OWNER);
    Assert.assertThat(samPermissionsImpl.accessPolicyResponseEntryToUserPermissions(Collections.singletonList(ownerPolicy)), CoreMatchers.is(Collections.singletonList(ownerPermission)));
    writerPermission = new Permission();
    writerPermission.setEmail(JANE_DOE_GMAIL_COM);
    writerPermission.setRole(Role.WRITER);
    readerPermission = new Permission();
    readerPermission.setEmail(JANE_DOE_GMAIL_COM);
    readerPermission.setRole(Role.READER);
    AccessPolicyMembership readerAccessPolicyMembership = new AccessPolicyMembership();
    readerAccessPolicyResponseEntry = new AccessPolicyResponseEntry();
    readerAccessPolicyResponseEntry.setPolicy(readerAccessPolicyMembership);
    readerAccessPolicyResponseEntry.setPolicyName(SamConstants.READ_POLICY);
    readerAccessPolicyResponseEntry.getPolicy().addRolesItem(SamConstants.READ_POLICY);
    readerAccessPolicyResponseEntry.getPolicy().addMemberEmailsItem(JANE_DOE_GMAIL_COM);
    final User.Profile profile = new User.Profile();
    profile.email = JANE_DOE_GMAIL_COM;
    final Map<String, User.Profile> map = new HashMap<>();
    map.put(TokenType.GOOGLE_COM.toString(), profile);
    when(userMock.getUserProfiles()).thenReturn(map);
}
Also used : User(io.dockstore.webservice.core.User) DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) HashMap(java.util.HashMap) Workflow(io.dockstore.webservice.core.Workflow) Token(io.dockstore.webservice.core.Token) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApiClient(io.swagger.sam.client.ApiClient) AccessPolicyMembership(io.swagger.sam.client.model.AccessPolicyMembership) TokenDAO(io.dockstore.webservice.jdbi.TokenDAO) AccessPolicyResponseEntry(io.swagger.sam.client.model.AccessPolicyResponseEntry) Permission(io.dockstore.webservice.permissions.Permission) ResourcesApi(io.swagger.sam.client.api.ResourcesApi) Before(org.junit.Before)

Example 3 with DockstoreWebserviceConfiguration

use of io.dockstore.webservice.DockstoreWebserviceConfiguration in project dockstore by dockstore.

the class GoogleHelperTest method isValidAudience.

@Test
public void isValidAudience() {
    final DockstoreWebserviceConfiguration config = new DockstoreWebserviceConfiguration();
    config.setGoogleClientID(AUDIENCE1);
    config.getExternalGoogleClientIdPrefixes().add(EXTERNAL_PREFIX);
    GoogleHelper.setConfig(config);
    final Tokeninfo tokeninfo = Mockito.mock(Tokeninfo.class);
    when(tokeninfo.getAudience()).thenReturn(AUDIENCE1).thenReturn(EXTERNAL_AUDIENCE).thenReturn(INVALID_AUDIENCE);
    Assert.assertTrue(GoogleHelper.isValidAudience(tokeninfo));
    Assert.assertTrue(GoogleHelper.isValidAudience(tokeninfo));
    Assert.assertFalse(GoogleHelper.isValidAudience(tokeninfo));
}
Also used : DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) Tokeninfo(com.google.api.services.oauth2.model.Tokeninfo) Test(org.junit.Test)

Example 4 with DockstoreWebserviceConfiguration

use of io.dockstore.webservice.DockstoreWebserviceConfiguration in project dockstore by dockstore.

the class PublicStateManagerIT method setupManager.

@BeforeClass
public static void setupManager() {
    DockstoreWebserviceConfiguration config = new DockstoreWebserviceConfiguration();
    config.getEsConfiguration().setHostname("localhost");
    config.getEsConfiguration().setPort(9200);
    PublicStateManagerIT.manager = PublicStateManager.getInstance();
    manager.setConfig(config);
}
Also used : DockstoreWebserviceConfiguration(io.dockstore.webservice.DockstoreWebserviceConfiguration) BeforeClass(org.junit.BeforeClass)

Aggregations

DockstoreWebserviceConfiguration (io.dockstore.webservice.DockstoreWebserviceConfiguration)4 BeforeClass (org.junit.BeforeClass)2 Tokeninfo (com.google.api.services.oauth2.model.Tokeninfo)1 Token (io.dockstore.webservice.core.Token)1 User (io.dockstore.webservice.core.User)1 Workflow (io.dockstore.webservice.core.Workflow)1 TokenDAO (io.dockstore.webservice.jdbi.TokenDAO)1 Permission (io.dockstore.webservice.permissions.Permission)1 ApiClient (io.swagger.sam.client.ApiClient)1 ResourcesApi (io.swagger.sam.client.api.ResourcesApi)1 AccessPolicyMembership (io.swagger.sam.client.model.AccessPolicyMembership)1 AccessPolicyResponseEntry (io.swagger.sam.client.model.AccessPolicyResponseEntry)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1