Exemplo n.º 1
0
func TestBasicAuth(t *testing.T) {
	// set current provider
	testProvider := &provider.TestProviderRunner{}
	provider.CurrentProvider = testProvider
	defer func() {
		//TODO: remove: as we arent updating all tests we need tos et current provider back to a
		//clean default one (I miss rspec before)
		provider.CurrentProvider = new(provider.TestProviderRunner)
	}()
	// setup expectations on current provider
	testProvider.On("SystemGet").Return(nil, nil)

	assert := assert.New(t)
	aws := test.StubAws(test.DescribeConvoxStackCycle("convox-test"))
	defer aws.Close()
	defer os.Setenv("PASSWORD", os.Getenv("PASSWORD"))
	defer os.Setenv("RACK", os.Getenv("RACK"))

	os.Setenv("PASSWORD", "keymaster")
	os.Setenv("RACK", "convox-test")

	req, _ := http.NewRequest("GET", "http://convox/system", nil)
	w := httptest.NewRecorder()
	controllers.HandlerFunc(w, req)

	if !assert.Equal(401, w.Code) {
		return
	}

	w = httptest.NewRecorder()
	req.SetBasicAuth("", "keymaster")
	controllers.HandlerFunc(w, req)

	assert.Equal(200, w.Code)
}
Exemplo n.º 2
0
func TestBasicAuth(t *testing.T) {
	models.TestProvider.On("SystemGet").Return(nil, nil)

	assert := assert.New(t)
	aws := test.StubAws(test.DescribeConvoxStackCycle("convox-test"))
	defer aws.Close()
	defer os.Setenv("PASSWORD", os.Getenv("PASSWORD"))
	defer os.Setenv("RACK", os.Getenv("RACK"))

	os.Setenv("PASSWORD", "keymaster")
	os.Setenv("RACK", "convox-test")

	req, _ := http.NewRequest("GET", "http://convox/system", nil)
	w := httptest.NewRecorder()
	controllers.HandlerFunc(w, req)

	if !assert.Equal(401, w.Code) {
		return
	}

	w = httptest.NewRecorder()
	req.SetBasicAuth("", "keymaster")
	controllers.HandlerFunc(w, req)

	assert.Equal(200, w.Code)
}
Exemplo n.º 3
0
func HTTPBody(method, url string, values url.Values) string {
	w := httptest.NewRecorder()
	req, err := buildRequest(method, url, values)

	if err != nil {
		return ""
	}

	controllers.HandlerFunc(w, req)
	return w.Body.String()
}
Exemplo n.º 4
0
func AssertStatus(t *testing.T, status int, method, url string, values url.Values) string {
	w := httptest.NewRecorder()
	req, err := buildRequest(method, url, values)

	if err != nil {
		t.Error(err)
		return ""
	}

	controllers.HandlerFunc(w, req)
	assert.Equal(t, status, w.Code)
	return w.Body.String()
}