<commit_before>package server

import (
	. "github.com/smartystreets/goconvey/convey"
	"gopkg.in/h2non/gock.v1"
	"net/http"
	"os"
	"testing"
)

func TestRouter(t *testing.T) {
	app := App()

	Convey("the index page", t, func() {

		Convey("should return OK", func() {
			req, _ := http.NewRequest("GET", "/", nil)
			res := executeRequest(app, req)

			So(res.Code, ShouldEqual, http.StatusOK)
			So(res.Body.String(), ShouldEqual, "Welcome!")
		})

		Convey("should have CORS headers", func() {
			origin := os.Getenv("CLIENT_ROOT")
			req, _ := http.NewRequest("GET", "/", nil)
			req.Header.Add("Origin", origin)
			res := executeRequest(app, req)

			So(res.Header().Get("Access-Control-Allow-Origin"), ShouldEqual, origin)
		})

		Convey("should not have global CORS headers", func() {
			req, _ := http.NewRequest("GET", "/", nil)
			req.Header.Add("Origin", "http://example.com/")
			res := executeRequest(app, req)

			So(res.Header().Get("Access-Control-Allow-Origin"), ShouldEqual, "")
		})

	})

	Convey("CAS authentication", t, func() {

		Convey("should redirect to CAS when not logged in", func() {
			gock.New("https://fed.princeton.edu").
				Get("/cas/validate").
				Reply(200).
				BodyString("no\n\n")
			defer gock.Off()

			req, _ := http.NewRequest("GET", "/login", nil)
			res := executeRequest(app, req)

			So(res.Code, ShouldEqual, http.StatusFound)
		})

		// TODO: Figure out why this test doesn't work
		SkipConvey("should return the proper user when logged in", func() {
			gock.New("https://fed.princeton.edu").
				Get("/cas/validate").
				Reply(200).
				BodyString("yes\ntestuser\n")
			defer gock.Off()

			req, _ := http.NewRequest("GET", "/login", nil)
			res := executeRequest(app, req)

			So(res.Code, ShouldEqual, http.StatusOK)
			So(res.Body.String(), ShouldEqual, "testuser")
		})

	})
}
<commit_msg>add additional sanity check for CORS headers<commit_after>package server

import (
	. "github.com/smartystreets/goconvey/convey"
	"gopkg.in/h2non/gock.v1"
	"net/http"
	"os"
	"testing"
)

func TestRouter(t *testing.T) {
	app := App()

	Convey("the index page", t, func() {

		Convey("should return OK", func() {
			req, _ := http.NewRequest("GET", "/", nil)
			res := executeRequest(app, req)

			So(res.Code, ShouldEqual, http.StatusOK)
			So(res.Body.String(), ShouldEqual, "Welcome!")
		})

		Convey("should have CORS headers", func() {
			origin := os.Getenv("CLIENT_ROOT")
			req, _ := http.NewRequest("GET", "/", nil)
			req.Header.Add("Origin", origin)
			res := executeRequest(app, req)

			So(origin, ShouldNotEqual, "")
			So(res.Header().Get("Access-Control-Allow-Origin"), ShouldEqual, origin)
		})

		Convey("should not have global CORS headers", func() {
			req, _ := http.NewRequest("GET", "/", nil)
			req.Header.Add("Origin", "http://example.com/")
			res := executeRequest(app, req)

			So(res.Header().Get("Access-Control-Allow-Origin"), ShouldEqual, "")
		})

	})

	Convey("CAS authentication", t, func() {

		Convey("should redirect to CAS when not logged in", func() {
			gock.New("https://fed.princet<EMAIL>").
				Get("/cas/validate").
				Reply(200).
				BodyString("no\n\n")
			defer gock.Off()

			req, _ := http.NewRequest("GET", "/login", nil)
			res := executeRequest(app, req)

			So(res.Code, ShouldEqual, http.StatusFound)
		})

		// TODO: Figure out why this test doesn't work
		SkipConvey("should return the proper user when logged in", func() {
			gock.New("https://fed.princeton.edu").
				Get("/cas/validate").
				Reply(200).
				BodyString("yes\ntestuser\n")
			defer gock.Off()

			req, _ := http.NewRequest("GET", "/login", nil)
			res := executeRequest(app, req)

			So(res.Code, ShouldEqual, http.StatusOK)
			So(res.Body.String(), ShouldEqual, "testuser")
		})

	})
}

{'fraction_non_alphanumeric': 0.18972857903139967, 'fraction_numerical': 0.004257583821181479, 'mean_word_length': 3.640740740740741, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5142155', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1310, 'n_words': 276}