energywebfoundation / ocn-node

Apache License 2.0
5 stars 4 forks source link

Cannot do custom module POST #18

Closed ewf-devops closed 4 years ago

ewf-devops commented 4 years ago

Original report by John Henderson (Bitbucket: [John Henderson](https://bitbucket.org/John Henderson), GitHub: jrhender).


Version last reproduced: 1.1.0-rc1

Expected results: Can make a POST request via a custom OCPI module

Observed results:

When making a POST request via a custom module, and signing the request body, the following logs are received:

2020-08-24 05:10:38.497 DEBUG 3437 --- [nio-8080-exec-6] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Writing [OcpiResponse(statusCode=2001, statusMessage=Invalid signature: Request has been modified., data=null (truncated)...]
2020-08-24 05:10:38.510 DEBUG 3437 --- [nio-8080-exec-6] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [snc.openchargingnetwork.node.models.exceptions.OcpiClientInvalidParametersException: Invalid signature: Request has been modified.]
2020-08-24 05:10:38.511 DEBUG 3437 --- [nio-8080-exec-6] o.s.web.servlet.DispatcherServlet        : Completed 400 BAD_REQUEST

Repro steps:

Run integration test in this commit: https://bitbucket.org/shareandcharge/ocn-node/commits/54477d9246fca7a1c91171c606dc4504ed56f6fb?at=bug/custom-module-post

ewf-devops commented 4 years ago

Original comment by John Henderson (Bitbucket: [John Henderson](https://bitbucket.org/John Henderson), GitHub: jrhender).


I propose a fix of assuming @RequestBody body can be parsed to Map<String,Any>? in CustomModulesController.customModuleMapping

@RestController
@RequestMapping("/ocpi/custom")
class CustomModulesController(private val requestHandlerBuilder: OcpiRequestHandlerBuilder) {

    @RequestMapping("/{interfaceRole}/{module}", "/{interfaceRole}/{module}/**/*")
    fun customModuleMapping(@RequestHeader("authorization") authorization: String,
                            @RequestHeader("OCN-Signature") signature: String? = null,
                            @RequestHeader("X-Request-ID") requestID: String,
                            @RequestHeader("X-Correlation-ID") correlationID: String,
                            @RequestHeader("OCPI-from-country-code") fromCountryCode: String,
                            @RequestHeader("OCPI-from-party-id") fromPartyID: String,
                            @RequestHeader("OCPI-to-country-code") toCountryCode: String,
                            @RequestHeader("OCPI-to-party-id") toPartyID: String,
                            @PathVariable interfaceRole: String,
                            @PathVariable module: String,
                            @RequestParam queryParams: Map<String, Any>,
                            @RequestBody body: String?,
                            request: HttpServletRequest): ResponseEntity<OcpiResponse<Any>> 

ewf-devops commented 4 years ago

Original comment by John Henderson (Bitbucket: [John Henderson](https://bitbucket.org/John Henderson), GitHub: jrhender).


@{557058:6d7b4493-acfb-4818-9eaf-956087983c24} or @{5efc3c2c54020e0ba82c6e64} , are you able to validate that this is a bug please?

ewf-devops commented 4 years ago

Original comment by Adam Staveley (Bitbucket: [Adam Staveley](https://bitbucket.org/Adam Staveley), GitHub: adamstaveley).


Strange, I thought I tested POST requests. I will look into it later this week.

ewf-devops commented 4 years ago

Original comment by Arzon Barua (Bitbucket: arzon.barua, ).


@{5efed1cdf34eae0ba6f4d21c} @{5efc3c2c54020e0ba82c6e64} I ran the integration test and also found error regarding the testMessagePost

ewf-devops commented 4 years ago

Original comment by John Henderson (Bitbucket: [John Henderson](https://bitbucket.org/John Henderson), GitHub: jrhender).


PR with fix has been merged into Develop