Documentation ¶
Index ¶
- Variables
- func CreateExternalServer(t *testing.T, test *BasicProxyTest) *httptest.Server
- func CreateExternalServerForPrivileged(t *testing.T, test BasicProxyTest) *httptest.Server
- func EchoResponseHandler(rw http.ResponseWriter, response *http.Response)
- func GetMockCompleteEnvVars() map[string]string
- func NewTestRequest(method, path string, body []byte) (*httptest.ResponseRecorder, *http.Request)
- func PrepareExternalServerCall(t *testing.T, c *controllers.SecureContext, testServer *httptest.Server, ...) (*httptest.ResponseRecorder, *http.Request, *web.Router)
- func VerifyExternalCallResponse(t *testing.T, response *httptest.ResponseRecorder, test *BasicProxyTest)
- type BasicConsoleUnitTest
- type BasicProxyTest
- type BasicSecureTest
- type Handler
- type MockSessionStore
- func (store MockSessionStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (store MockSessionStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (store *MockSessionStore) ResetSessionData(data map[string]interface{}, sessionName string)
- func (store MockSessionStore) Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error
- type ResponseContentTester
Constants ¶
This section is empty.
Variables ¶
var InvalidTokenData = map[string]interface{}{ "token": oauth2.Token{Expiry: (time.Now()).Add(-1 * time.Minute), AccessToken: "invalidsampletoken"}, }
InvalidTokenData is a dataset which represents an invalid token. Useful for unit tests.
var ValidTokenData = map[string]interface{}{ "token": oauth2.Token{Expiry: time.Time{}, AccessToken: "sampletoken"}, }
ValidTokenData is a dataset which represents a valid token. Useful for unit tests.
Functions ¶
func CreateExternalServer ¶
func CreateExternalServer(t *testing.T, test *BasicProxyTest) *httptest.Server
CreateExternalServer creates a test server that should reply with the given parameters assuming that the incoming request matches what we want.
func CreateExternalServerForPrivileged ¶
func CreateExternalServerForPrivileged(t *testing.T, test BasicProxyTest) *httptest.Server
CreateExternalServerForPrivileged creates a test server that should reply with the given parameters assuming that the incoming request matches what we want. This call will be with the HighPrivilegedOauthClient.
func EchoResponseHandler ¶
func EchoResponseHandler(rw http.ResponseWriter, response *http.Response)
EchoResponseHandler is a normal handler for responses received from the proxy requests.
func GetMockCompleteEnvVars ¶
GetMockCompleteEnvVars is just a commonly used env vars object that contains non-empty values for all the fields of the EnvVars struct.
func NewTestRequest ¶
NewTestRequest is a helper function that creates a sample request with the given input parameters.
func PrepareExternalServerCall ¶
func PrepareExternalServerCall(t *testing.T, c *controllers.SecureContext, testServer *httptest.Server, fullURL string, test BasicProxyTest) (*httptest.ResponseRecorder, *http.Request, *web.Router)
PrepareExternalServerCall creates all the things that we will use when we send the request to the external server. This includes setting up the routes, create a test response recorder and a test request.
func VerifyExternalCallResponse ¶
func VerifyExternalCallResponse(t *testing.T, response *httptest.ResponseRecorder, test *BasicProxyTest)
VerifyExternalCallResponse will verify the test response with what was expected by the test.
Types ¶
type BasicConsoleUnitTest ¶
type BasicConsoleUnitTest struct { // Name of the tests TestName string // Set of env vars to set up the settings. EnvVars map[string]string // Ending location of request. Location string Code int SessionData map[string]interface{} }
BasicConsoleUnitTest is Basic Unit Test Information.
type BasicProxyTest ¶
type BasicProxyTest struct { BasicSecureTest // RequestPath is the path that our test client should send. RequestPath string // RequestBody is the body that our test client should send. RequestBody []byte // Handlers is the list of handlers to use to respond for the server. Handlers []Handler // RequestMethod is the type of method that our test client should send. RequestMethod string // RequestHeaders is a map of headers that our test client should send. RequestHeaders map[string]string }
BasicProxyTest contains information for what our test 'external' server should do when the proxy methods contact it.
type BasicSecureTest ¶
type BasicSecureTest struct { BasicConsoleUnitTest ExpectedCode int ExpectedResponse ResponseContentTester ExpectedLocation string ExpectedHeaders map[string]string }
BasicSecureTest contains info like BasicConsoleUnitTest. TODO consolidate BasicConsoleUnitTest and BasicSecureTest
type Handler ¶
type Handler struct { // The response the test 'external' Cloud Foundry server should send back. Response string // The code the test 'external' Cloud Foundry server should send back. ResponseCode int // ExpectedPath is the path that the test 'external' Cloud Foundry server we setup should receive. // This is useful as we translate our endpoints to conform with the Cloud Foundry APIs. // e.g. our endpoint: /uaa/userinfo & Cloud Foundry endpoint: /userinfo ExpectedPath string // RequestMethod is the method the external server should be waiting for. RequestMethod string }
Handler is a specific handler for the test server.
type MockSessionStore ¶
type MockSessionStore struct { Session *sessions.Session Options *sessions.Options // contains filtered or unexported fields }
MockSessionStore represents an easily fillable session store that implements gorilla's session store interface.
func CreateRouterWithMockSession ¶
func CreateRouterWithMockSession(sessionData map[string]interface{}, envVars map[string]string) (*web.Router, *MockSessionStore)
CreateRouterWithMockSession will create a settings with the appropriate envVars and load the mock session with the session data.
func (MockSessionStore) Get ¶
Get simply returns the session that has pre populated beforehand with ResetSessionData or will return nil if the session name that is given is 'nilSession'
func (MockSessionStore) New ¶
New returns the current session. Does not create a new one. Not needed for mock sessions.
func (*MockSessionStore) ResetSessionData ¶
func (store *MockSessionStore) ResetSessionData(data map[string]interface{}, sessionName string)
ResetSessionData zero initializes the MockSessionStore and then will copy the input session data into it.
func (MockSessionStore) Save ¶
func (store MockSessionStore) Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error
Save returns nil error. We save session data by using ResetSessionData
type ResponseContentTester ¶
type ResponseContentTester interface { // Check should return true if the resp matches the expected false, and false otherwise Check(t assert.TestingT, resp string) bool // Display returns the expected string suitable for an error message Display() string }
ResponseContentTester can check a response for equivalency
func NewJSONResponseContentTester ¶
func NewJSONResponseContentTester(expected string) ResponseContentTester
NewJSONResponseContentTester creates a content matcher where the content being tested is JSON.
func NewStringContentTester ¶
func NewStringContentTester(expected string) ResponseContentTester
NewStringContentTester returns an content matcher where the content being tested is a string.