AddMfa adds a mock handler to the given server which returns a login response and a 200 status code on GET requests to the /login endpoint. It adds another mock handler to validate the given password and MFA token upon POST requests to /oauth/token.
(server *Server, password string, mfaToken string)
| 119 | // on GET requests to the /login endpoint. It adds another mock handler to validate the given password and MFA token |
| 120 | // upon POST requests to /oauth/token. |
| 121 | func AddMfa(server *Server, password string, mfaToken string) { |
| 122 | getLoginResponse := fmt.Sprintf(`{ |
| 123 | "app": { |
| 124 | "version": "4.28.0" |
| 125 | }, |
| 126 | "showLoginLinks": true, |
| 127 | "links": { |
| 128 | "uaa": "%[1]s", |
| 129 | "passwd": "/forgot_password", |
| 130 | "login": "%[1]s", |
| 131 | "register": "/create_account" |
| 132 | }, |
| 133 | "zone_name": "uaa", |
| 134 | "entityID": "some-host-name.example.com", |
| 135 | "commit_id": "8917980", |
| 136 | "idpDefinitions": {}, |
| 137 | "prompts": { |
| 138 | "username": [ |
| 139 | "text", |
| 140 | "Email" |
| 141 | ], |
| 142 | "password": [ |
| 143 | "password", |
| 144 | "Password" |
| 145 | ], |
| 146 | "passcode": [ |
| 147 | "password", |
| 148 | "Temporary Authentication Code ( Get one at %[1]s/passcode )" |
| 149 | ], |
| 150 | "mfaCode": [ |
| 151 | "password", |
| 152 | "MFA Code ( Register at %[1]s )" |
| 153 | ] |
| 154 | }, |
| 155 | "timestamp": "2019-02-19T18:08:02+0000" |
| 156 | }`, server.URL()) |
| 157 | |
| 158 | server.RouteToHandler(http.MethodGet, "/login", |
| 159 | RespondWith(http.StatusOK, getLoginResponse), |
| 160 | ) |
| 161 | |
| 162 | server.RouteToHandler(http.MethodPost, "/oauth/token", makeMFAValidator(password, mfaToken)) |
| 163 | |
| 164 | } |
| 165 | |
| 166 | func makeMFAValidator(password string, mfaToken string) http.HandlerFunc { |
| 167 | return func(res http.ResponseWriter, req *http.Request) { |
nothing calls this directly
no test coverage detected