| 647 | } |
| 648 | |
| 649 | func refreshTokenAPIEndPoint(unauthorizedBody string, secondReqResp testnet.TestResponse) http.HandlerFunc { |
| 650 | return func(writer http.ResponseWriter, request *http.Request) { |
| 651 | var jsonResponse string |
| 652 | |
| 653 | bodyBytes, err := ioutil.ReadAll(request.Body) |
| 654 | if err != nil || string(bodyBytes) != "expected body" { |
| 655 | writer.WriteHeader(http.StatusInternalServerError) |
| 656 | return |
| 657 | } |
| 658 | |
| 659 | switch request.Header.Get("Authorization") { |
| 660 | case initialAccessToken: |
| 661 | writer.WriteHeader(http.StatusUnauthorized) |
| 662 | jsonResponse = unauthorizedBody |
| 663 | case refreshedAccessToken: |
| 664 | writer.WriteHeader(secondReqResp.Status) |
| 665 | jsonResponse = secondReqResp.Body |
| 666 | default: |
| 667 | writer.WriteHeader(http.StatusInternalServerError) |
| 668 | } |
| 669 | |
| 670 | fmt.Fprintln(writer, jsonResponse) |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | func createAuthenticationRepository(apiServer *httptest.Server, authServer *httptest.Server) (coreconfig.ReadWriter, authentication.Repository) { |
| 675 | config := testconfig.NewRepository() |