Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. package main
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "os"
  6. "path"
  7. "testing"
  8. "github.com/zenazn/goji"
  9. )
  10. var testCSPHeaders = map[string]string{
  11. "Content-Security-Policy": "default-src 'none'; style-src 'self';",
  12. "Referrer-Policy": "strict-origin-when-cross-origin",
  13. "X-Frame-Options": "SAMEORIGIN",
  14. }
  15. func TestContentSecurityPolicy(t *testing.T) {
  16. Config.siteURL = "http://linx.example.org/"
  17. Config.filesDir = path.Join(os.TempDir(), generateBarename())
  18. Config.metaDir = Config.filesDir + "_meta"
  19. Config.maxSize = 1024 * 1024 * 1024
  20. Config.noLogs = true
  21. Config.siteName = "linx"
  22. Config.contentSecurityPolicy = testCSPHeaders["Content-Security-Policy"]
  23. Config.referrerPolicy = testCSPHeaders["Referrer-Policy"]
  24. Config.xFrameOptions = testCSPHeaders["X-Frame-Options"]
  25. mux := setup()
  26. w := httptest.NewRecorder()
  27. req, err := http.NewRequest("GET", "/", nil)
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. goji.Use(ContentSecurityPolicy(CSPOptions{
  32. policy: testCSPHeaders["Content-Security-Policy"],
  33. referrerPolicy: testCSPHeaders["Referrer-Policy"],
  34. frame: testCSPHeaders["X-Frame-Options"],
  35. }))
  36. mux.ServeHTTP(w, req)
  37. for k, v := range testCSPHeaders {
  38. if w.HeaderMap[k][0] != v {
  39. t.Fatalf("%s header did not match expected value set by middleware", k)
  40. }
  41. }
  42. }