Skip to content

Commit

Permalink
feat!: add mfa to password and user name update
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-martins-mx committed Jan 17, 2024
1 parent 8cb9b4b commit 18c02dd
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.mx.path.gateway.accessor.Accessor;
import com.mx.path.gateway.accessor.AccessorConfiguration;
import com.mx.path.gateway.accessor.AccessorResponse;
import com.mx.path.model.mdx.model.MdxList;
import com.mx.path.model.mdx.model.challenges.Challenge;
import com.mx.path.model.mdx.model.profile.Password;
import com.mx.path.model.mdx.model.profile.Profile;
Expand Down Expand Up @@ -177,7 +176,7 @@ public AccessorResponse<Profile> update(Profile profile) {
*/
@GatewayAPI
@API(description = "Update user's user name")
public AccessorResponse<Void> updateUserName(UserName userName) {
public AccessorResponse<UserName> updateUserName(UserName userName) {
throw new AccessorMethodNotImplementedException();
}

Expand All @@ -189,7 +188,7 @@ public AccessorResponse<Void> updateUserName(UserName userName) {
*/
@GatewayAPI
@API(description = "Update user's password")
public AccessorResponse<MdxList<Challenge>> updatePassword(Password password) {
public AccessorResponse<Password> updatePassword(Password password) {
throw new AccessorMethodNotImplementedException();
}

Expand All @@ -202,8 +201,7 @@ public AccessorResponse<MdxList<Challenge>> updatePassword(Password password) {
*/
@GatewayAPI
@API(description = "Update user's password")
public AccessorResponse<MdxList<Challenge>> updatePasswordResume(String challengeId, Challenge challenge) {
public AccessorResponse<Password> updatePasswordResume(String challengeId, Challenge challenge) {
throw new AccessorMethodNotImplementedException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class BaseController {
// NO INSTANCE VARIABLES! Controllers are Singletons

public static final String MDX_MEDIA = "application/vnd.mx.mdx.v6+json;charset=UTF-8";

public static final String MDX_MEDIA_NEXT = "application/vnd.mx.mdx.v6.next+json;charset=UTF-8";
public static final String MDX_ONDEMAND_MEDIA = "application/vnd.moneydesktop.mdx.v5+xml";

private static ThreadLocal<Gateway> gatewayThreadLocal = new ThreadLocal<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,75 @@ public final ResponseEntity<Email> deleteEmail(@PathVariable("emailId") String e

@RequestMapping(value = "/users/{userId}/profile/update_password", method = RequestMethod.PUT)
public final ResponseEntity<MdxList<Challenge>> updatePassword(@RequestBody Password password) {
AccessorResponse<MdxList<Challenge>> response = gateway().profiles().updatePassword(password);
if (response.getResult() != null && response.getResult().size() != 0) {
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED);
AccessorResponse<Password> response = gateway().profiles().updatePassword(password);

Boolean hasChallenges = response.getResult() != null && response.getResult().getChallenges() != null;
AccessorResponse<MdxList<Challenge>> coercedResponse = AccessorResponse.<MdxList<Challenge>>builder()
.status(response.getStatus())
.exception(response.getException())
.result(hasChallenges ? new MdxList<>(response.getResult().getChallenges()) : null)
.build();

response.getHeaders().forEach(coercedResponse::withHeader);

if (coercedResponse.getResult() != null && coercedResponse.getResult().size() != 0) {
return new ResponseEntity<>(coercedResponse.getResult().wrapped(), createMultiMapForResponse(coercedResponse.getHeaders()), HttpStatus.ACCEPTED);
}
return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
return new ResponseEntity<>(createMultiMapForResponse(coercedResponse.getHeaders()), HttpStatus.NO_CONTENT);
}

@RequestMapping(value = "/users/{userId}/profile/update_password/challenges/{challengeId}", method = RequestMethod.PUT)
public final ResponseEntity<MdxList<Challenge>> updatePasswordResume(@PathVariable("challengeId") String challengeId, @RequestBody Challenge challenge) {
AccessorResponse<MdxList<Challenge>> response = gateway().profiles().updatePasswordResume(challengeId, challenge);
if (response.getResult() != null && response.getResult().size() != 0) {
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED);
AccessorResponse<Password> response = gateway().profiles().updatePasswordResume(challengeId, challenge);

Boolean hasChallenges = response.getResult() != null && response.getResult().getChallenges() != null;
AccessorResponse<MdxList<Challenge>> coercedResponse = AccessorResponse.<MdxList<Challenge>>builder()
.status(response.getStatus())
.exception(response.getException())
.result(hasChallenges ? new MdxList<>(response.getResult().getChallenges()) : null)
.build();

response.getHeaders().forEach(coercedResponse::withHeader);

if (coercedResponse.getResult() != null && coercedResponse.getResult().size() != 0) {
return new ResponseEntity<>(coercedResponse.getResult().wrapped(), createMultiMapForResponse(coercedResponse.getHeaders()), HttpStatus.ACCEPTED);
}
return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
return new ResponseEntity<>(createMultiMapForResponse(coercedResponse.getHeaders()), HttpStatus.NO_CONTENT);
}

@RequestMapping(value = "/users/{userId}/profile/update_username", method = RequestMethod.PUT)
public final ResponseEntity<?> updateUserName(@RequestBody UserName updateUserInfo) {
AccessorResponse<Void> response = gateway().profiles().updateUserName(updateUserInfo);
AccessorResponse<UserName> response = gateway().profiles().updateUserName(updateUserInfo);
return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
}

@RequestMapping(value = "/users/{userId}/profile/update_password", method = RequestMethod.PUT, produces = MDX_MEDIA_NEXT)
public final ResponseEntity<Password> updatePasswordNext(@RequestBody Password password) {
AccessorResponse<Password> response = gateway().profiles().updatePassword(password);
Password result = response.getResult();
if (result != null && result.getChallenges() != null && result.getChallenges().size() > 0) {
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED);
}
return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
}

@RequestMapping(value = "/users/{userId}/profile/update_password/challenges/{challengeId}", method = RequestMethod.PUT, produces = MDX_MEDIA_NEXT)
public final ResponseEntity<Password> updatePasswordResumeNext(@PathVariable("challengeId") String challengeId, @RequestBody Challenge challenge) {
AccessorResponse<Password> response = gateway().profiles().updatePasswordResume(challengeId, challenge);
Password result = response.getResult();
if (result != null && result.getChallenges() != null && result.getChallenges().size() > 0) {
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED);
}
return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
}

@RequestMapping(value = "/users/{userId}/profile/update_username", method = RequestMethod.PUT, produces = MDX_MEDIA_NEXT)
public final ResponseEntity<UserName> updateUserNameNext(@RequestBody UserName updateUserInfo) {
AccessorResponse<UserName> response = gateway().profiles().updateUserName(updateUserInfo);
UserName result = response.getResult();
if (result != null && result.getChallenges() != null && result.getChallenges().size() > 0) {
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED);
}
return new ResponseEntity<>(createMultiMapForResponse(response.getHeaders()), HttpStatus.NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ class ProfilesControllerTest extends Specification {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<MdxList<Challenge>>().withResult(new MdxList<>().tap {
add(new Challenge())
def mockResponse = new AccessorResponse<Password>().withResult(new Password().tap {
setChallenges(new MdxList<Challenge>().tap { add(new Challenge()) })
})

doReturn(mockResponse).when(profileGateway).updatePassword(any())
Expand All @@ -443,7 +443,7 @@ class ProfilesControllerTest extends Specification {
def response = subject.updatePassword(new Password())

then:
response.body == mockResponse.result
response.body == mockResponse.result.challenges
response.body.wrapped
response.statusCode == HttpStatus.ACCEPTED
}
Expand All @@ -468,8 +468,8 @@ class ProfilesControllerTest extends Specification {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<MdxList<Challenge>>().withResult(new MdxList<>().tap {
add(new Challenge())
def mockResponse = new AccessorResponse<Password>().withResult(new Password().tap {
setChallenges(new MdxList<Challenge>().tap { add(new Challenge()) })
})

doReturn(mockResponse).when(profileGateway).updatePasswordResume(any(), any())
Expand All @@ -478,7 +478,7 @@ class ProfilesControllerTest extends Specification {
def response = subject.updatePasswordResume("1", new Challenge())

then:
response.body == mockResponse.result
response.body == mockResponse.result.challenges
response.body.wrapped
response.statusCode == HttpStatus.ACCEPTED
}
Expand All @@ -499,6 +499,76 @@ class ProfilesControllerTest extends Specification {
response.statusCode == HttpStatus.NO_CONTENT
}

def "updatePasswordNext_implemented - 202"() {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<Password>().withResult(new Password().tap {
setChallenges(new MdxList<Challenge>().tap { add(new Challenge()) })
})

doReturn(mockResponse).when(profileGateway).updatePassword(any())

when:
def response = subject.updatePasswordNext(new Password())

then:
response.body == mockResponse.result
response.body.wrapped
response.statusCode == HttpStatus.ACCEPTED
}

def "updatePasswordNext_implemented - 204"() {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<Void>()

doReturn(mockResponse).when(profileGateway).updatePassword(any())

when:
def response = subject.updatePasswordNext(new Password())

then:
response.body == mockResponse.result
response.statusCode == HttpStatus.NO_CONTENT
}

def "updatePasswordResumeNext_implemented - 202"() {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<Password>().withResult(new Password().tap {
setChallenges(new MdxList<Challenge>().tap { add(new Challenge()) })
})

doReturn(mockResponse).when(profileGateway).updatePasswordResume(any(), any())

when:
def response = subject.updatePasswordResumeNext("1", new Challenge())

then:
response.body == mockResponse.result
response.body.wrapped
response.statusCode == HttpStatus.ACCEPTED
}

def "updatePasswordResumeNext_implemented - 204"() {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<Void>()

doReturn(mockResponse).when(profileGateway).updatePasswordResume(any(), any())

when:
def response = subject.updatePasswordResumeNext("1", new Challenge())

then:
response.body == mockResponse.result
response.statusCode == HttpStatus.NO_CONTENT
}

def "deleteEmail_implemented"() {
given:
ProfilesController.setGateway(gateway)
Expand Down Expand Up @@ -527,4 +597,39 @@ class ProfilesControllerTest extends Specification {
then:
response.statusCode == HttpStatus.NO_CONTENT
}

def "updateUserNameNext_implemented - 202"() {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<UserName>().withResult(new UserName().tap {
setChallenges(new MdxList<Challenge>().tap { add(new Challenge()) })
})

doReturn(mockResponse).when(profileGateway).updateUserName(any())

when:
def response = subject.updateUserNameNext(new UserName())

then:
response.body == mockResponse.result
response.body.wrapped
response.statusCode == HttpStatus.ACCEPTED
}

def "updateUserNameNext_implemented - 204"() {
given:
ProfilesController.setGateway(gateway)

def mockResponse = new AccessorResponse<Void>()

doReturn(mockResponse).when(profileGateway).updateUserName(any())

when:
def response = subject.updateUserNameNext(new UserName())

then:
response.body == mockResponse.result
response.statusCode == HttpStatus.NO_CONTENT
}
}

0 comments on commit 18c02dd

Please sign in to comment.