forked from eclipse-sw360/sw360
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eclipse-sw360#2535 from siemens/fix/RestTestCases
fix(rest): Fixing the rest test cases Reviewed-by: mishra.gaurav@siemens.com Tested-by: mishra.gaurav@siemens.com
- Loading branch information
Showing
63 changed files
with
816 additions
and
1,318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 0 additions & 196 deletions
196
.../eclipse/sw360/rest/authserver/security/basicauth/Sw360LiferayAuthenticationProvider.java
This file was deleted.
Oops, something went wrong.
78 changes: 55 additions & 23 deletions
78
.../test/java/org/eclipse/sw360/rest/authserver/GrantTypeClientCredentialsBasicAuthTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,63 @@ | ||
/* | ||
* Copyright Siemens AG, 2019. Part of the SW360 Portal Project. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
* SPDX-FileCopyrightText: © 2024 Siemens AG | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.sw360.rest.authserver; | ||
|
||
import org.junit.Before; | ||
import org.eclipse.sw360.rest.authserver.IntegrationTestBase; | ||
import org.junit.Test; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.*; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class GrantTypeClientCredentialsBasicAuthTest extends IntegrationTestBase { | ||
|
||
private final String clientId = "trusted-sw360-client"; | ||
private final String clientSecret = "sw360-secret"; | ||
private final TestRestTemplate restTemplate = new TestRestTemplate(); | ||
|
||
@Test | ||
public void successfulTokenRetrieval() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); | ||
headers.setBasicAuth(clientId, clientSecret, StandardCharsets.UTF_8); | ||
|
||
HttpEntity<String> request = new HttpEntity<>("grant_type=client_credentials", headers); | ||
String url = "http://localhost:" + port + "/oauth2/token"; | ||
|
||
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class); | ||
|
||
assertThat(response.getStatusCode(), is(HttpStatus.OK)); | ||
} | ||
|
||
@Test | ||
public void unauthorizedDueToInvalidCredentials() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); | ||
headers.setBasicAuth("invalidClientId", "invalidClientSecret", StandardCharsets.UTF_8); | ||
|
||
HttpEntity<String> request = new HttpEntity<>("grant_type=client_credentials", headers); | ||
String url = "http://localhost:" + port + "/oauth2/token"; | ||
|
||
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class); | ||
|
||
assertThat(response.getStatusCode(), is(HttpStatus.UNAUTHORIZED)); | ||
} | ||
|
||
import java.io.IOException; | ||
@Test | ||
public void badRequestDueToMissingGrantType() { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); | ||
headers.setBasicAuth(clientId, clientSecret, StandardCharsets.UTF_8); | ||
|
||
/** | ||
* A POST request for an access token with grant type 'client_credentials' and | ||
* basic auth should be possible. | ||
*/ | ||
public class GrantTypeClientCredentialsBasicAuthTest extends GrantTypeClientCredentialsTestBase { | ||
HttpEntity<String> request = new HttpEntity<>("", headers); | ||
String url = "http://localhost:" + port + "/oauth2/token"; | ||
|
||
@Before | ||
public void before() throws IOException { | ||
String url = "http://localhost:" + String.valueOf(port) + "/oauth/token?grant_type=" + PARAMETER_GRANT_TYPE | ||
+ "&client_id=" + testClient.getClientId(); | ||
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class); | ||
|
||
responseEntity = new TestRestTemplate(testClient.getClientId(), testClient.getClientSecret()).postForEntity(url, | ||
null, String.class); | ||
assertThat(response.getStatusCode(), is(HttpStatus.BAD_REQUEST)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.