@ExtendWith({ RepositoryManagementTestExecutionListener.class,

              ArtifactManagementTestExecutionListener.class })
@Test
public void addUserTest(@NpmRepository(repositoryId = REPOSITORY_RELEASES)
                                Repository repository)
{
    String url = getContextBaseUrl() + "/storages/{storageId}/{repositoryId}/" + NpmLayoutProvider.NPM_USER_PATH +
                 "{username}";
    String basicAuth = "Basic YWRtaW46cGFzc3dvcmQ=";
    final String storageId = repository.getStorage().getId();
    final String repositoryId = repository.getId();
    NpmUser strongboxUser1 = new NpmUser("admin", "password");
    NpmUser strongboxUser2 = new NpmUser("deployer", "password");
    NpmUser nonStrongboxUser = new NpmUser("notARealUser", "notARealPassword");
    //can login with strongbox user
    mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE)
           .body(strongboxUser1)
           .when()
           .put(url, storageId, repositoryId, strongboxUser1.getName())
           .peek()
           .then()
           .statusCode(HttpStatus.CREATED.value());
    //can login with another strongbox user after login
    mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE)
           .body(strongboxUser2)
           .when()
           .put(url, storageId, repositoryId, strongboxUser2.getName())
           .peek()
           .then()
           .statusCode(HttpStatus.CREATED.value());
    //can't login when the url username differs from the body
    mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE)
           .body(strongboxUser1)
           .when()
           .put(url, storageId, repositoryId, nonStrongboxUser.getName())
           .peek()
           .then()
           .statusCode(HttpStatus.UNAUTHORIZED.value());
    //can't login with non strongbox user when basic auth is strongbox user
    mockMvc.header(HttpHeaders.AUTHORIZATION, basicAuth)
           .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
           .contentType(MediaType.APPLICATION_JSON_VALUE)
           .body(nonStrongboxUser)
           .when()
           .put(url, storageId, repositoryId, nonStrongboxUser.getName())
           .then()
           .statusCode(HttpStatus.UNAUTHORIZED.value());
    //can login with strongbox user when basic auth is strongbox user
    mockMvc.header(HttpHeaders.AUTHORIZATION, basicAuth)
           .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
           .contentType(MediaType.APPLICATION_JSON_VALUE)
           .body(strongboxUser1)
           .when()
           .put(url, storageId, repositoryId, strongboxUser1.getName())
           .then()
           .statusCode(HttpStatus.CREATED.value());
    //can't login with non-strongbox user
    mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE)
           .body(nonStrongboxUser)
           .when()
           .put(url, storageId, repositoryId, nonStrongboxUser.getName())
           .peek()
           .then()
           .statusCode(HttpStatus.UNAUTHORIZED.value());
}