MockOpenIDDiscoveryServer is the in-memory openID discovery server.
| 74 | |
| 75 | // MockOpenIDDiscoveryServer is the in-memory openID discovery server. |
| 76 | type MockOpenIDDiscoveryServer struct { |
| 77 | Port int |
| 78 | URL string |
| 79 | server *http.Server |
| 80 | |
| 81 | // How many times openIDCfg is called, use this number to verify cache takes effect. |
| 82 | OpenIDHitNum uint64 |
| 83 | |
| 84 | // How many times jwtPubKey is called, use this number to verify cache takes effect. |
| 85 | PubKeyHitNum uint64 |
| 86 | |
| 87 | // The mock server will return an error for the first number of hits for public key, this is used |
| 88 | // to simulate network errors and test the retry logic in jwks resolver for public key fetch. |
| 89 | ReturnErrorForFirstNumHits uint64 |
| 90 | |
| 91 | // The mock server will start to return an error after the first number of hits for public key, |
| 92 | // this is used to simulate network errors and test the refresh logic in jwks resolver. |
| 93 | ReturnErrorAfterFirstNumHits uint64 |
| 94 | |
| 95 | // The mock server will start to return a successful response after the first number of hits for public key, |
| 96 | // this is used to simulate network errors and test the refresh logic in jwks resolver. Note the idea is to |
| 97 | // use this in combination with ReturnErrorAfterFirstNumHits to simulate something like this: |
| 98 | // { success, success, error, error, success, success } |
| 99 | ReturnSuccessAfterFirstNumHits uint64 |
| 100 | |
| 101 | // The mock server will start to return an error after the first number of hits for public key, |
| 102 | // this is used to simulate network errors and test the refresh logic in jwks resolver. |
| 103 | ReturnReorderedKeyAfterFirstNumHits uint64 |
| 104 | |
| 105 | // If both TLSKeyFile and TLSCertFile are set, Start() will attempt to start a HTTPS server. |
| 106 | TLSKeyFile string |
| 107 | TLSCertFile string |
| 108 | |
| 109 | // Artificious delay added by the mock server on handling requests |
| 110 | timeout time.Duration |
| 111 | } |
| 112 | |
| 113 | // StartNewServer creates a mock openID discovery server and starts it |
| 114 | func StartNewServer() (*MockOpenIDDiscoveryServer, error) { |
nothing calls this directly
no outgoing calls
no test coverage detected