Skip to content

Commit

Permalink
Remove dummy token generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sabahirfan authored and RustyHMCTS committed Feb 8, 2024
1 parent 173bdb0 commit 9b43050
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 158 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.hmcts.opal.authentication.exception.AuthenticationError;
import uk.gov.hmcts.opal.authentication.model.AccessTokenResponse;
import uk.gov.hmcts.opal.authentication.model.SecurityToken;
import uk.gov.hmcts.opal.authentication.service.AccessTokenService;
import uk.gov.hmcts.opal.authentication.service.AzureDummyTokenService;
import uk.gov.hmcts.opal.dto.AppMode;
import uk.gov.hmcts.opal.exception.OpalApiException;
import uk.gov.hmcts.opal.launchdarkly.FeatureToggleService;
import uk.gov.hmcts.opal.service.DynamicConfigService;

Expand All @@ -32,7 +26,6 @@ public class TestingSupportController {

private final DynamicConfigService dynamicConfigService;
private final FeatureToggleService featureToggleService;
private final AzureDummyTokenService azureDummyTokenService;
private final AccessTokenService accessTokenService;

@GetMapping("/app-mode")
Expand All @@ -57,22 +50,6 @@ public ResponseEntity<String> getFeatureValue(@PathVariable String featureKey) {
return ResponseEntity.ok(this.featureToggleService.getFeatureValue(featureKey));
}

@PostMapping("/handle-oauth-code")
@Operation(summary = "Generates dummy JWT token for tests on PRs")
public SecurityToken handleOauthCode(@RequestParam(value = "code", required = false) String code) {
String userName = "opal-test";
try {
String accessToken = this.azureDummyTokenService.generateAzureJwtToken(userName);
var securityTokenBuilder = SecurityToken.builder()
.accessToken(accessToken);

return securityTokenBuilder.build();
} catch (Exception e) {
throw new OpalApiException(AuthenticationError.FAILED_TO_OBTAIN_ACCESS_TOKEN, e);
}

}

@GetMapping("/token/test-user")
public ResponseEntity<AccessTokenResponse> getToken() {
return ResponseEntity.ok(this.accessTokenService.getTestUserToken());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package uk.gov.hmcts.opal.controllers;

import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import uk.gov.hmcts.opal.authentication.model.AccessTokenResponse;
import uk.gov.hmcts.opal.authentication.model.SecurityToken;
import uk.gov.hmcts.opal.authentication.service.AccessTokenService;
import uk.gov.hmcts.opal.authentication.service.AzureDummyTokenService;
import uk.gov.hmcts.opal.dto.AppMode;
import uk.gov.hmcts.opal.exception.OpalApiException;
import uk.gov.hmcts.opal.launchdarkly.FeatureToggleService;
import uk.gov.hmcts.opal.service.DynamicConfigService;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@SpringBootTest(
Expand All @@ -45,8 +39,6 @@ class TestingSupportControllerTest {
@MockBean
private FeatureToggleService featureToggleService;

@MockBean
private AzureDummyTokenService azureDummyTokenService;

@MockBean
private AccessTokenService accessTokenService;
Expand Down Expand Up @@ -94,34 +86,6 @@ void getFeatureFlagValue() {
assertEquals("value", response.getBody());
}

@SneakyThrows
@Test
void testHandleOauthCode() {
String username = "opal-test";
String token = "abc123";

when(azureDummyTokenService.generateAzureJwtToken(anyString()))
.thenReturn(token);

SecurityToken result = controller.handleOauthCode(username);

assertEquals(token, result.getAccessToken());
verify(azureDummyTokenService).generateAzureJwtToken(username);
}

@SneakyThrows
@Test
void testHandleOauthCode_error() {
when(azureDummyTokenService.generateAzureJwtToken(anyString()))
.thenThrow(new RuntimeException("Error!"));

assertThrows(OpalApiException.class, () -> {
controller.handleOauthCode(null);
});

verify(azureDummyTokenService).generateAzureJwtToken(anyString());
}

@Test
public void getToken_shouldReturnResponse() {
// Arrange
Expand Down

0 comments on commit 9b43050

Please sign in to comment.