@Test public void should_accept_valid_basic_auth_uppercase_case_prefix() { when(settings.getHerokuApiPassword()).thenReturn("password"); controller.validateBasicAuth("BASIC Y29kZWt2YXN0OnBhc3N3b3Jk"); }
void validateBasicAuth(String authentication) throws BadCredentialsException { logger.debug("authentication={}", authentication); val credentials = "codekvast:" + settings.getHerokuApiPassword(); val expected = "Basic " + new String( Base64.getEncoder().encode(credentials.getBytes()), StandardCharsets.UTF_8); val normalizedAuth = authentication.replaceAll("^[Bb][Aa][Ss][Ii][Cc] ", "Basic "); if (!normalizedAuth.equals(expected)) { throw new BadCredentialsException("Invalid credentials: " + authentication); } }
HerokuResourcesController { void validateBasicAuth(String authentication) throws BadCredentialsException { logger.debug("authentication={}", authentication); val credentials = "codekvast:" + settings.getHerokuApiPassword(); val expected = "Basic " + new String( Base64.getEncoder().encode(credentials.getBytes()), StandardCharsets.UTF_8); val normalizedAuth = authentication.replaceAll("^[Bb][Aa][Ss][Ii][Cc] ", "Basic "); if (!normalizedAuth.equals(expected)) { throw new BadCredentialsException("Invalid credentials: " + authentication); } } }
HerokuResourcesController { void validateBasicAuth(String authentication) throws BadCredentialsException { logger.debug("authentication={}", authentication); val credentials = "codekvast:" + settings.getHerokuApiPassword(); val expected = "Basic " + new String( Base64.getEncoder().encode(credentials.getBytes()), StandardCharsets.UTF_8); val normalizedAuth = authentication.replaceAll("^[Bb][Aa][Ss][Ii][Cc] ", "Basic "); if (!normalizedAuth.equals(expected)) { throw new BadCredentialsException("Invalid credentials: " + authentication); } }  }
HerokuResourcesController { void validateBasicAuth(String authentication) throws BadCredentialsException { logger.debug("authentication={}", authentication); val credentials = "codekvast:" + settings.getHerokuApiPassword(); val expected = "Basic " + new String( Base64.getEncoder().encode(credentials.getBytes()), StandardCharsets.UTF_8); val normalizedAuth = authentication.replaceAll("^[Bb][Aa][Ss][Ii][Cc] ", "Basic "); if (!normalizedAuth.equals(expected)) { throw new BadCredentialsException("Invalid credentials: " + authentication); } }  @ExceptionHandler ResponseEntity<String> onBadCredentialsException(BadCredentialsException e); @ExceptionHandler ResponseEntity<String> onHerokuException(HerokuException e); @PostMapping(path = "/heroku/resources") ResponseEntity<HerokuProvisionResponse> provision(
      @Valid @RequestBody HerokuProvisionRequest request,
      @RequestHeader(AUTHORIZATION) String authorization); @PutMapping(path = "/heroku/resources/{id}") ResponseEntity<String> changePlan(
      @PathVariable("id") String id,
      @Valid @RequestBody HerokuChangePlanRequest request,
      @RequestHeader(AUTHORIZATION) String auth); @DeleteMapping(path = "/heroku/resources/{id}") ResponseEntity<String> deprovision(
      @PathVariable("id") String id, @RequestHeader(AUTHORIZATION) String auth); }
HerokuResourcesController { void validateBasicAuth(String authentication) throws BadCredentialsException { logger.debug("authentication={}", authentication); val credentials = "codekvast:" + settings.getHerokuApiPassword(); val expected = "Basic " + new String( Base64.getEncoder().encode(credentials.getBytes()), StandardCharsets.UTF_8); val normalizedAuth = authentication.replaceAll("^[Bb][Aa][Ss][Ii][Cc] ", "Basic "); if (!normalizedAuth.equals(expected)) { throw new BadCredentialsException("Invalid credentials: " + authentication); } }  @ExceptionHandler ResponseEntity<String> onBadCredentialsException(BadCredentialsException e); @ExceptionHandler ResponseEntity<String> onHerokuException(HerokuException e); @PostMapping(path = "/heroku/resources") ResponseEntity<HerokuProvisionResponse> provision(
      @Valid @RequestBody HerokuProvisionRequest request,
      @RequestHeader(AUTHORIZATION) String authorization); @PutMapping(path = "/heroku/resources/{id}") ResponseEntity<String> changePlan(
      @PathVariable("id") String id,
      @Valid @RequestBody HerokuChangePlanRequest request,
      @RequestHeader(AUTHORIZATION) String auth); @DeleteMapping(path = "/heroku/resources/{id}") ResponseEntity<String> deprovision(
      @PathVariable("id") String id, @RequestHeader(AUTHORIZATION) String auth);  }