Search in sources :

Example 1 with UserData

use of org.eclipse.openvsx.entities.UserData in project openvsx by eclipse.

the class EclipseServiceTest method testRevokePublisherAgreementByAdmin.

@Test
public void testRevokePublisherAgreementByAdmin() throws Exception {
    var user = mockUser();
    var eclipseData = new EclipseData();
    user.setEclipseData(eclipseData);
    eclipseData.personId = "test";
    eclipseData.publisherAgreement = new EclipseData.PublisherAgreement();
    eclipseData.publisherAgreement.isActive = true;
    var admin = new UserData();
    admin.setLoginName("admin");
    admin.setEclipseToken(new AuthToken());
    admin.getEclipseToken().accessToken = "67890";
    Mockito.when(tokens.getActiveToken(admin, "eclipse")).thenReturn(admin.getEclipseToken());
    eclipse.revokePublisherAgreement(user, admin);
    assertThat(user.getEclipseData().publisherAgreement.isActive).isFalse();
}
Also used : UserData(org.eclipse.openvsx.entities.UserData) AuthToken(org.eclipse.openvsx.entities.AuthToken) EclipseData(org.eclipse.openvsx.entities.EclipseData) Test(org.junit.jupiter.api.Test)

Example 2 with UserData

use of org.eclipse.openvsx.entities.UserData in project openvsx by eclipse.

the class EclipseServiceTest method mockUser.

private UserData mockUser() {
    var user = new UserData();
    user.setLoginName("test");
    user.setEclipseToken(new AuthToken());
    user.getEclipseToken().accessToken = "12345";
    Mockito.when(tokens.getActiveToken(user, "eclipse")).thenReturn(user.getEclipseToken());
    return user;
}
Also used : UserData(org.eclipse.openvsx.entities.UserData) AuthToken(org.eclipse.openvsx.entities.AuthToken)

Example 3 with UserData

use of org.eclipse.openvsx.entities.UserData in project openvsx by eclipse.

the class RegistryAPITest method mockForPublish.

private void mockForPublish(String mode) {
    var token = mockAccessToken();
    if (mode.equals("invalid")) {
        token.setActive(false);
    }
    var namespace = new Namespace();
    namespace.setName("foo");
    Mockito.when(repositories.findNamespace("foo")).thenReturn(namespace);
    if (mode.equals("existing")) {
        var extension = new Extension();
        extension.setName("bar");
        var extVersion = new ExtensionVersion();
        extVersion.setExtension(extension);
        extVersion.setVersion("1");
        extVersion.setActive(true);
        Mockito.when(repositories.findExtension("bar", namespace)).thenReturn(extension);
        Mockito.when(repositories.findVersion("1", extension)).thenReturn(extVersion);
    }
    Mockito.when(repositories.countActiveReviews(any(Extension.class))).thenReturn(0l);
    Mockito.when(repositories.findVersions(any(Extension.class))).thenReturn(Streamable.empty());
    Mockito.when(repositories.findActiveVersions(any(Extension.class))).thenReturn(Streamable.empty());
    Mockito.when(repositories.getVersionStrings(any(Extension.class))).thenReturn(Streamable.empty());
    Mockito.when(repositories.getActiveVersionStrings(any(Extension.class))).thenReturn(Streamable.empty());
    Mockito.when(repositories.findFilesByType(any(ExtensionVersion.class), anyCollection())).thenReturn(Streamable.empty());
    if (mode.equals("owner")) {
        var ownerMem = new NamespaceMembership();
        ownerMem.setUser(token.getUser());
        ownerMem.setNamespace(namespace);
        ownerMem.setRole(NamespaceMembership.ROLE_OWNER);
        Mockito.when(repositories.findMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(Streamable.of(ownerMem));
        Mockito.when(repositories.countMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(1l);
        Mockito.when(repositories.findMembership(token.getUser(), namespace)).thenReturn(ownerMem);
        Mockito.when(repositories.countMemberships(token.getUser(), namespace)).thenReturn(1l);
    } else if (mode.equals("contributor") || mode.equals("sole-contributor") || mode.equals("existing")) {
        var contribMem = new NamespaceMembership();
        contribMem.setUser(token.getUser());
        contribMem.setNamespace(namespace);
        contribMem.setRole(NamespaceMembership.ROLE_CONTRIBUTOR);
        Mockito.when(repositories.findMembership(token.getUser(), namespace)).thenReturn(contribMem);
        Mockito.when(repositories.countMemberships(token.getUser(), namespace)).thenReturn(1l);
        if (mode.equals("contributor")) {
            var otherUser = new UserData();
            otherUser.setLoginName("other_user");
            var ownerMem = new NamespaceMembership();
            ownerMem.setUser(otherUser);
            ownerMem.setNamespace(namespace);
            ownerMem.setRole(NamespaceMembership.ROLE_OWNER);
            Mockito.when(repositories.findMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(Streamable.of(ownerMem));
            Mockito.when(repositories.countMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(1l);
        } else {
            Mockito.when(repositories.findMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(Streamable.empty());
            Mockito.when(repositories.countMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(0l);
        }
    } else if (mode.equals("privileged") || mode.equals("unrelated")) {
        var otherUser = new UserData();
        otherUser.setLoginName("other_user");
        var ownerMem = new NamespaceMembership();
        ownerMem.setUser(otherUser);
        ownerMem.setNamespace(namespace);
        ownerMem.setRole(NamespaceMembership.ROLE_OWNER);
        Mockito.when(repositories.findMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(Streamable.of(ownerMem));
        Mockito.when(repositories.countMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(1l);
        if (mode.equals("privileged")) {
            token.getUser().setRole(UserData.ROLE_PRIVILEGED);
        }
    } else {
        Mockito.when(repositories.findMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(Streamable.empty());
        Mockito.when(repositories.countMemberships(namespace, NamespaceMembership.ROLE_OWNER)).thenReturn(0l);
    }
}
Also used : Extension(org.eclipse.openvsx.entities.Extension) UserData(org.eclipse.openvsx.entities.UserData) NamespaceMembership(org.eclipse.openvsx.entities.NamespaceMembership) Namespace(org.eclipse.openvsx.entities.Namespace) ExtensionVersion(org.eclipse.openvsx.entities.ExtensionVersion)

Aggregations

UserData (org.eclipse.openvsx.entities.UserData)3 AuthToken (org.eclipse.openvsx.entities.AuthToken)2 EclipseData (org.eclipse.openvsx.entities.EclipseData)1 Extension (org.eclipse.openvsx.entities.Extension)1 ExtensionVersion (org.eclipse.openvsx.entities.ExtensionVersion)1 Namespace (org.eclipse.openvsx.entities.Namespace)1 NamespaceMembership (org.eclipse.openvsx.entities.NamespaceMembership)1 Test (org.junit.jupiter.api.Test)1