133728e barerepo 1mo
1
package httpd
133728e barerepo 1mo
3
import (
133728e barerepo 1mo
4
"encoding/json"
133728e barerepo 1mo
5
"net/http/httptest"
133728e barerepo 1mo
6
"strings"
133728e barerepo 1mo
7
"testing"
133728e barerepo 1mo
9
"github.com/barerepo/server/internal/config"
133728e barerepo 1mo
12
func TestALargeFileClientIsToldWhyRatherThanGivenA404(t *testing.T) {
133728e barerepo 1mo
13
for _, path := range []string{
133728e barerepo 1mo
14
"/john/johnbot/info/lfs/objects/batch",
133728e barerepo 1mo
15
"/john/johnbot.git/info/lfs/objects/batch",
133728e barerepo 1mo
16
"/john/johnbot/info/lfs",
133728e barerepo 1mo
17
} {
133728e barerepo 1mo
18
r, ok := parseGitPath(path)
133728e barerepo 1mo
19
if !ok || !r.LFS {
133728e barerepo 1mo
20
t.Fatalf("parseGitPath(%q) did not recognise a large file request", path)
133728e barerepo 1mo
22
if r.Owner != "john" || r.Name != "johnbot" {
133728e barerepo 1mo
23
t.Errorf("parseGitPath(%q) read %s/%s", path, r.Owner, r.Name)
133728e barerepo 1mo
27
s := &Server{Cfg: config.Default()}
133728e barerepo 1mo
28
w := httptest.NewRecorder()
133728e barerepo 1mo
29
s.refuseLFS(w)
133728e barerepo 1mo
30
if w.Code != 501 {
133728e barerepo 1mo
31
t.Errorf("answered %d, want 501", w.Code)
133728e barerepo 1mo
33
if got := w.Header().Get("Content-Type"); got != "application/vnd.git-lfs+json" {
133728e barerepo 1mo
34
t.Errorf("content type is %q, which git-lfs will not read as its own", got)
133728e barerepo 1mo
36
var body struct {
133728e barerepo 1mo
37
Message string `json:"message"`
133728e barerepo 1mo
39
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
133728e barerepo 1mo
40
t.Fatalf("the body is not json git-lfs can read: %v", err)
133728e barerepo 1mo
42
if !strings.Contains(body.Message, "off on this server") {
133728e barerepo 1mo
43
t.Errorf("the message does not say why: %q", body.Message)