You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2020/11/10 12:44:59 UTC
[archiva-redback-core] branch master updated: Fixing return codes
for user service v2
This is an automated email from the ASF dual-hosted git repository.
martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva-redback-core.git
The following commit(s) were added to refs/heads/master by this push:
new fa2cce0 Fixing return codes for user service v2
fa2cce0 is described below
commit fa2cce07a9194edbfcaf8a7cec76c221c425641d
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Tue Nov 10 13:44:44 2020 +0100
Fixing return codes for user service v2
---
.../archiva/redback/rest/services/v2/DefaultUserService.java | 11 ++++++++++-
.../archiva/redback/rest/services/v2/UserServiceTest.java | 9 ++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java
index 5b01109..8e7518f 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/v2/DefaultUserService.java
@@ -220,6 +220,9 @@ public class DefaultUserService
public UserInfo createUser( User user )
throws RedbackServiceException
{
+ if (user==null) {
+ throw new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_ID_EMPTY ), 422 );
+ }
UserInfo result;
if ( Arrays.binarySearch( INVALID_CREATE_USER_NAMES, user.getUserId( ) ) >= 0 )
{
@@ -307,6 +310,9 @@ public class DefaultUserService
public void deleteUser( String userId )
throws RedbackServiceException
{
+ if (StringUtils.isEmpty( userId )) {
+ throw new RedbackServiceException( MessageKeys.ERR_USER_ID_EMPTY, 404 );
+ }
try
{
@@ -348,6 +354,9 @@ public class DefaultUserService
public UserInfo getUser( String userId )
throws RedbackServiceException
{
+ if (StringUtils.isEmpty( userId)) {
+ throw new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_ID_EMPTY ), 404 );
+ }
try
{
if ( "guest".equals( userId ) )
@@ -359,7 +368,7 @@ public class DefaultUserService
}
catch ( UserNotFoundException e )
{
- return null;
+ throw new RedbackServiceException( ErrorMessage.of( MessageKeys.ERR_USER_NOT_FOUND ), 404 );
}
catch ( UserManagerException e )
{
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/v2/UserServiceTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/v2/UserServiceTest.java
index eab9e2b..c673582 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/v2/UserServiceTest.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/v2/UserServiceTest.java
@@ -48,6 +48,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.inject.Inject;
import javax.ws.rs.ForbiddenException;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.MediaType;
import java.util.Collection;
import java.util.Collections;
@@ -564,7 +565,13 @@ public class UserServiceTest
{
getUserService( getAdminAuthzHeader( ) ).deleteUser( "toto" );
getUserService( getAdminAuthzHeader( ) ).removeFromCache( "toto" );
- assertNull( getUserService( getAdminAuthzHeader( ) ).getUser( "toto" ) );
+ try
+ {
+ getUserService( getAdminAuthzHeader( ) ).getUser( "toto" );
+ assertTrue( false, "404 should be thrown for non existing resource" );
+ } catch ( NotFoundException e ) {
+ assertEquals( 404, e.getResponse( ).getStatus( ) );
+ }
}
}