@@ -555,3 +555,58 @@ func TestProcessCookieFailIfRefreshSetAndCookieExpired(t *testing.T) {
555555 t.Errorf("expected nil session %#v", session)
556556 }
557557}
558+
559+func NewAuthOnlyEndpointTest() *ProcessCookieTest {
560+ pc_test := NewProcessCookieTestWithDefaults()
561+ pc_test.req, _ = http.NewRequest("GET",
562+ pc_test.opts.ProxyPrefix + "/auth", nil)
563+ return pc_test
564+}
565+
566+func TestAuthOnlyEndpointAccepted(t *testing.T) {
567+ test := NewAuthOnlyEndpointTest()
568+ startSession := &providers.SessionState{
569+ Email: "michael.bland@gsa.gov", AccessToken: "my_access_token"}
570+ test.SaveSession(startSession, time.Now())
571+
572+ test.proxy.ServeHTTP(test.rw, test.req)
573+ assert.Equal(t, http.StatusAccepted, test.rw.Code)
574+ bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
575+ assert.Equal(t, "", string(bodyBytes))
576+}
577+
578+func TestAuthOnlyEndpointUnauthorizedOnNoCookieSetError(t *testing.T) {
579+ test := NewAuthOnlyEndpointTest()
580+
581+ test.proxy.ServeHTTP(test.rw, test.req)
582+ assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
583+ bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
584+ assert.Equal(t, "unauthorized request\n", string(bodyBytes))
585+}
586+
587+func TestAuthOnlyEndpointUnauthorizedOnExpiration(t *testing.T) {
588+ test := NewAuthOnlyEndpointTest()
589+ test.proxy.CookieExpire = time.Duration(24) * time.Hour
590+ reference := time.Now().Add(time.Duration(25) * time.Hour * -1)
591+ startSession := &providers.SessionState{
592+ Email: "michael.bland@gsa.gov", AccessToken: "my_access_token"}
593+ test.SaveSession(startSession, reference)
594+
595+ test.proxy.ServeHTTP(test.rw, test.req)
596+ assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
597+ bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
598+ assert.Equal(t, "unauthorized request\n", string(bodyBytes))
599+}
600+
601+func TestAuthOnlyEndpointUnauthorizedOnEmailValidationFailure(t *testing.T) {
602+ test := NewAuthOnlyEndpointTest()
603+ startSession := &providers.SessionState{
604+ Email: "michael.bland@gsa.gov", AccessToken: "my_access_token"}
605+ test.SaveSession(startSession, time.Now())
606+ test.validate_user = false
607+
608+ test.proxy.ServeHTTP(test.rw, test.req)
609+ assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
610+ bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
611+ assert.Equal(t, "unauthorized request\n", string(bodyBytes))
612+}