### Question:
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);  }### Answer:
@Test(expected = BadCredentialsException.class) public void should_reject_malformed_basic_auth() { when(settings.getHerokuApiPassword()).thenReturn("password"); controller.validateBasicAuth("foobar"); }
@Test(expected = BadCredentialsException.class) public void should_reject_invalid_basic_auth() { when(settings.getHerokuApiPassword()).thenReturn("password"); controller.validateBasicAuth("Basic foobar"); }
@Test public void should_accept_valid_basic_auth_mixed_case_prefix() { when(settings.getHerokuApiPassword()).thenReturn("password"); controller.validateBasicAuth("BaSiC Y29kZWt2YXN0OnBhc3N3b3Jk"); }
@Test public void should_accept_valid_basic_auth_lower_case_prefix() { when(settings.getHerokuApiPassword()).thenReturn("password"); controller.validateBasicAuth("basic Y29kZWt2YXN0OnBhc3N3b3Jk"); }
@Test public void should_accept_valid_basic_auth_uppercase_case_prefix() { when(settings.getHerokuApiPassword()).thenReturn("password"); controller.validateBasicAuth("BASIC Y29kZWt2YXN0OnBhc3N3b3Jk"); }