Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

WIP: Fix/search 1892 #440

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

WIP: Fix/search 1892 #440

wants to merge 9 commits into from

Conversation

agazzarini
Copy link

@agazzarini agazzarini commented Dec 6, 2019

  • Minor formatting, formal refacroting + additional illegal character in group id
  • Added unit tests for the issue

@@ -357,57 +356,6 @@ public void testGetGroup() throws Exception

}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for removing the test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @michaelsuzukisagi it was a test added by me. After talking with Meenal, we realized the tests have to be implemented in the TAS RESTAPI project.

So I left the test class as it was, (because the services tested by GroupsTest are not what we are fixing, they belong to some old api), and I'm implementing them in the other repository

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer having more unit tests over integration tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit tests for this issue.

@agazzarini agazzarini self-assigned this Dec 9, 2019
@CLAassistant
Copy link

CLAassistant commented Apr 2, 2020

CLA assistant check
All committers have signed the CLA.

@amohammedalfresco
Copy link
Contributor

I'm having confusion.

I could see there's a place where the new invalid character " would have been just appended to this array: https://github.com/Alfresco/alfresco-remote-api/blob/master/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java#L90

There's already an existing test to check for this array of invalid characters at: https://github.com/Alfresco/alfresco-remote-api/blob/master/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java#L1457 without the need to write separate unit test.

As this branch is pretty old and the fact it has other changes that am not sure of. I will now fork a new branch from master and append the array with " in source code and it's test to simplify the fix.

@@ -48,6 +48,7 @@
org.alfresco.rest.api.tests.AuthenticationsTest.class,
org.alfresco.rest.api.tests.DiscoveryApiTest.class,
org.alfresco.rest.api.tests.GroupsTest.class,
org.alfresco.rest.api.impl.GroupsImplTest.class,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this and update the test in GroupsTest.java line 1453.

@@ -52,6 +52,8 @@
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;

import static java.util.Arrays.stream;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Comment on lines +1 to +83
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.api.impl;

import org.alfresco.repo.domain.permissions.Authority;
import org.alfresco.repo.security.authority.AuthorityDAO;
import org.alfresco.rest.api.impl.GroupsImpl;
import org.alfresco.rest.api.tests.client.data.Group;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PermissionService;
import org.junit.Test;
import org.mockito.Mockito;

import static org.mockito.Matchers.*;
import static org.mockito.Mockito.when;

public class GroupsImplTest
{
private GroupsImpl groupsImpl;

@Test(expected = IllegalArgumentException.class)
public void createGroupCheckWithillegalCharacterInGroupId() {
groupsImpl = new GroupsImpl();
Group group= new Group();
String groupId="GROUP_Identifier\"WithIllegalChar";
group.setId(groupId);
group.setDisplayName(groupId);
AuthorityDAO authorityDAO = Mockito.mock(AuthorityDAO.class);
when(authorityDAO.getAuthorityDisplayName(anyString())).thenReturn(groupId);
AuthorityService authorityService = Mockito.mock(AuthorityService.class);
groupsImpl.setAuthorityService(authorityService);
groupsImpl.setAuthorityDAO(authorityDAO);
when(authorityService.authorityExists(anyString())).thenReturn(false);
when(authorityService.getName(any(AuthorityType.class), anyString())).thenReturn("test");
when(authorityService.createAuthority(any(AuthorityType.class), anyString(), anyString(), anySet())).thenReturn(PermissionService.ALL_AUTHORITIES);
Parameters parameters = Mockito.mock(Parameters.class);
groupsImpl.create(group, parameters);
}

@Test()
public void createGroupCheckWithlegalCharacterInGroupId() {
groupsImpl = new GroupsImpl();
Group group= new Group();
String groupId="GROUP_IdentifierWithLegalChar";
group.setId(groupId);
group.setDisplayName(groupId);
AuthorityDAO authorityDAO = Mockito.mock(AuthorityDAO.class);
when(authorityDAO.getAuthorityDisplayName(anyString())).thenReturn(groupId);
AuthorityService authorityService = Mockito.mock(AuthorityService.class);
groupsImpl.setAuthorityService(authorityService);
groupsImpl.setAuthorityDAO(authorityDAO);
when(authorityService.authorityExists(anyString())).thenReturn(false);
when(authorityService.getName(any(AuthorityType.class), anyString())).thenReturn("test");
when(authorityService.createAuthority(any(AuthorityType.class), anyString(), anyString(), anySet())).thenReturn(PermissionService.ALL_AUTHORITIES);
Parameters parameters = Mockito.mock(Parameters.class);
groupsImpl.create(group, parameters);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this class and update the test in GroupsTest.java line 1453.

@amohammedalfresco amohammedalfresco changed the title Fix/search 1892 WIP: Fix/search 1892 Apr 3, 2020
@amohammedalfresco
Copy link
Contributor

@agazzarini: I've raised another PR #603 in regards to my previous observations. To avoid confusion, do you consider if we can close this PR? Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants