Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spacebin v2 #418

Merged
merged 82 commits into from
Jun 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
2a572e7
docs(readme.md): update
lukewhrit Jul 19, 2021
b4dbc0b
fix: repo transfer
lukewhrit Nov 2, 2021
a415743
docs(readme.md): remove discord widget
Nov 3, 2021
a081d2d
docs(readme.md): fix Codacy badge
Nov 3, 2021
f4ae3fc
fix: update copyright years and packages
lukewhrit Aug 9, 2022
c8227eb
fix: another repo transfer
lukewhrit Aug 9, 2022
90dbdc9
build(go): upgrade to go 1.19
lukewhrit Nov 17, 2022
bd6106d
docs(readme.md): Update readme
lukewhrit Nov 19, 2022
a96bb1d
refactor(initialize-v1-rewrite): clean up code and transition to new …
lukewhrit Nov 23, 2022
944fd99
feat(util): added WriteError and WriteJSON helper functions
lukewhrit Nov 24, 2022
ddafebe
build: use makefile instead of mage
lukewhrit Dec 17, 2022
85f78bd
refactor(config): use purely env-based config instead of previous koa…
lukewhrit Dec 17, 2022
d5f3592
build(docker): use latest go version
lukewhrit Dec 17, 2022
b91fa8f
ci(workflows): "publish to docker" job for release workflow
lukewhrit Dec 17, 2022
ec6a8ce
feat(routes): fetch document route
lukewhrit Dec 17, 2022
b3368f5
feat(routes): fetch raw document
lukewhrit Dec 17, 2022
183729b
fix(routes): return after sending HTTP error
lukewhrit Dec 17, 2022
fd9cd2e
fix(HandleBody): fix content-type switching
lukewhrit Dec 17, 2022
18a475f
feat(document): dictionary words for ids
lukewhrit Dec 19, 2022
4c43b55
docs: tidy
lukewhrit Dec 19, 2022
43be3fd
docs(readme.md): simplify
lukewhrit Dec 20, 2022
3037aa4
perf: remove unused dependencies and upgrade
lukewhrit Dec 20, 2022
9534df9
build(dependabot): change target branch
lukewhrit Dec 20, 2022
72feb57
refactor: remove extension and content hash fields
lukewhrit Dec 20, 2022
89f600d
ci(workflows): update workflows to use make instead of mage
lukewhrit Dec 20, 2022
e4a03bf
refactor(util): simpler response writer
lukewhrit Dec 20, 2022
916d76e
feat: config route
lukewhrit Dec 20, 2022
82238b0
fix: add backwards-compatibility routes
lukewhrit Dec 20, 2022
d4e2e79
feat: structured logging using zerolog
lukewhrit Dec 20, 2022
fe70a99
ci(build-workflow): use correct make command
lukewhrit Dec 20, 2022
33bf02d
fix: add headers from old fiber app
lukewhrit Dec 21, 2022
7117a77
ci(workflows): add test and codecov workflow
lukewhrit Dec 21, 2022
39deaad
test(util): add basic tests for id generator
lukewhrit Dec 21, 2022
e54e493
ci(workflows): upgrade codeql
lukewhrit Dec 21, 2022
05c743c
docs(readme.md): replace codacy license with codecov
lukewhrit Dec 21, 2022
7376cce
fix(routes): use correct route for fetch document
lukewhrit Dec 21, 2022
47a6bea
refactor(database): remove ORM and move to pure sqlx + pq
lukewhrit Dec 21, 2022
a7a5a62
fix(routes): update routes to use new database implementation
lukewhrit Dec 21, 2022
8c5f804
fix(routes): 404 errors when a document isnt found
lukewhrit Dec 21, 2022
9bfea6e
fix: add cors support
lukewhrit Dec 21, 2022
5ca2ff8
fix(database): properly handle connection error before migrating
lukewhrit Dec 23, 2022
b0faab8
feat: setup go-chi/httprate for ratelimiter
lukewhrit Dec 23, 2022
fd04b54
feat(server): graceful shutdown
lukewhrit Jan 11, 2023
acc5208
test: setup test infra
lukewhrit Jan 11, 2023
c0bc713
test(server/config): check equality without connection_uri field
lukewhrit Jan 15, 2023
444699f
test(server): load config into server struct for testing
lukewhrit Jan 15, 2023
22d9231
test(config): implement tests for Load function
lukewhrit Jan 15, 2023
049e894
docs(readme): update
lukewhrit Jan 15, 2023
caa5bcd
build(makefile): remove no_sqlite flag and add cleanup task
lukewhrit Jan 15, 2023
51edf96
docs: update license year
lukewhrit Jan 15, 2023
adc9005
refactor(server): access database via Server struct
lukewhrit Jan 15, 2023
8994675
fix: use errors.Is instead of generic comparison for errors
lukewhrit Jan 15, 2023
df7d86d
fix: use s.Config instead of config.Config
lukewhrit Jan 15, 2023
b5639ea
feat(server): custom named documents
lukewhrit Jan 21, 2023
80988ca
feat(web): condense pulsar and spirit into a single project repo
lukewhrit Feb 11, 2023
a7c1cdb
feat(web): Copy Document button
lukewhrit Feb 11, 2023
55716a0
feat(web): Syntax highlighting
lukewhrit Feb 11, 2023
60959dc
docs(issue-templates): server related issues only no more
lukewhrit Feb 11, 2023
0d5500c
feat: static file serving
lukewhrit Jun 29, 2023
44dbed7
feat(web): embed static files into binary
lukewhrit Aug 5, 2023
4bfc46b
fix: add robots.txt file
lukewhrit Aug 7, 2023
c14837f
fix(server/fetch): use html/template so that content is properly esca…
lukewhrit Aug 7, 2023
11d1f5c
refactor(web): hljs v11.8.0
lukewhrit Aug 7, 2023
d17b73f
feat(fetch): override hljs auto-detection with optional file extensio…
lukewhrit Aug 7, 2023
3ce301a
ci(workers): fix job names
lukewhrit Aug 7, 2023
96390a9
refactor: upgrade go, docker, and actions versions
lukewhrit Aug 7, 2023
aa0fdb2
refactor: replace sqlx with stock database/sql
lukewhrit Aug 7, 2023
fdc0cfc
refactor: support alternative drivers besides postgres
lukewhrit Aug 7, 2023
ff962fe
docs: update copyright
lukewhrit Aug 7, 2023
706fde2
perf: upgrade packages
lukewhrit Aug 8, 2023
7cfd0c0
feat: mock database driver
lukewhrit Aug 8, 2023
73d1ef8
test(server): add fetch document test
lukewhrit Aug 8, 2023
7a9e07a
test(server/fetch_test.go): use UTC for all times in test
lukewhrit Aug 8, 2023
7f0b759
test(util): add tests for CountLines, ValidateBody, ParseRatelimiterS…
lukewhrit Aug 8, 2023
9e0ab3c
test(util/rl_parse_test.go): add tests for invalid number syntax and …
lukewhrit Aug 8, 2023
c6ad5e1
docs(readme.md): fix build status badge
lukewhrit Aug 8, 2023
1787bdd
test(util/helpers_test.go): add tests for WriteJSON and WriteError
lukewhrit Aug 8, 2023
fd6025a
test(server_test.go): add test for RegisterHeaders
lukewhrit Aug 9, 2023
a159de6
test(helpers): body parsing functions
lukewhrit Jun 23, 2024
bf28b4d
fix: update packages; copyright year -> 2024
lukewhrit Jun 23, 2024
b2e2145
build(workflows): update Go version
lukewhrit Jun 23, 2024
2339881
merge
lukewhrit Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(server_test.go): add test for RegisterHeaders
  • Loading branch information
lukewhrit committed Aug 9, 2023
commit fd6025ad051ff2b63a6e475888294781c9946ddf
7 changes: 4 additions & 3 deletions internal/server/config_test.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
* limitations under the License.
*/

package server
package server_test

import (
"encoding/json"
@@ -25,6 +25,7 @@ import (

"github.com/orca-group/spirit/internal/config"
"github.com/orca-group/spirit/internal/database"
"github.com/orca-group/spirit/internal/server"
"github.com/stretchr/testify/require"
)

@@ -49,7 +50,7 @@ var mockConfig = config.Cfg{
// then executes the request by calling ServeHTTP in the router
// after which the handler writes the response to the response recorder
// which we can then inspect.
func executeRequest(req *http.Request, s *Server) *httptest.ResponseRecorder {
func executeRequest(req *http.Request, s *server.Server) *httptest.ResponseRecorder {
rr := httptest.NewRecorder()
s.Router.ServeHTTP(rr, req)

@@ -67,7 +68,7 @@ func checkResponseCode(t *testing.T, expected, actual int) {
func TestConfig(t *testing.T) {
mockDB := database.NewMockDatabase(t)

s := NewServer(&mockConfig, mockDB)
s := server.NewServer(&mockConfig, mockDB)
s.MountHandlers()

req, _ := http.NewRequest("GET", "/config", nil)
2 changes: 1 addition & 1 deletion internal/server/create_test.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
* limitations under the License.
*/

package server
package server_test

import "testing"

5 changes: 3 additions & 2 deletions internal/server/fetch_test.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
* limitations under the License.
*/

package server
package server_test

import (
"encoding/json"
@@ -24,6 +24,7 @@ import (
"time"

"github.com/orca-group/spirit/internal/database"
"github.com/orca-group/spirit/internal/server"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
@@ -36,7 +37,7 @@ type DocumentResponse struct {
func TestFetch(t *testing.T) {
mockDB := database.NewMockDatabase(t)

s := NewServer(&mockConfig, mockDB)
s := server.NewServer(&mockConfig, mockDB)
s.MountHandlers()

mockDB.EXPECT().GetDocument(mock.Anything, "12345678").Return(database.Document{
52 changes: 52 additions & 0 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2020-2023 Luke Whritenour

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package server_test

import (
"net/http"
"testing"

"github.com/orca-group/spirit/internal/database"
"github.com/orca-group/spirit/internal/server"
"github.com/stretchr/testify/require"
)

func TestRegisterHeaders(t *testing.T) {
s := server.NewServer(&mockConfig, &database.MockDatabase{})

s.RegisterHeaders()
s.Router.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write([]byte("."))
})

req, _ := http.NewRequest(http.MethodGet, "/", nil)
res := executeRequest(req, s)

// Ensure 200
checkResponseCode(t, http.StatusOK, res.Result().StatusCode)

require.Equal(t, "noopen", res.Result().Header.Get("X-Download-Options"))
require.Equal(t, "off", res.Result().Header.Get("X-DNS-Prefetch-Control"))
require.Equal(t, "SAMEORIGIN", res.Result().Header.Get("X-Frame-Options"))
require.Equal(t, "1; mode=block", res.Result().Header.Get("X-XSS-Protection"))
require.Equal(t, "nosniff", res.Result().Header.Get("X-Content-Type-Options"))
require.Equal(t, "no-referrer-when-downgrade", res.Result().Header.Get("Referrer-Policy"))
require.Equal(t, "max-age=31536000; includeSubDomains; preload", res.Result().Header.Get("Strict-Transport-Security"))
require.Equal(t, "default-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'; script-src 'self' 'unsafe-inline';", res.Result().Header.Get("Content-Security-Policy"))
}