~bigbes/sr-ht-dolt

ref: bd2d8a3680e62716440ea0165d2271d79f9d526e sr-ht-dolt/cmd/doltsrht/graphql_test.go -rw-r--r-- 1.4 KiB
bd2d8a36 — Eugene Blikh doltsrht: serve /query and the api-meta.json beside it 3 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"encoding/json"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"sourcecraft.dev/bigbes/sr-ht-ecore/apimeta"

	"sourcecraft.dev/bigbes/sr-ht-dolt/authn"
)

// The scope this service advertises and the scope it enforces are the same fact
// written twice: meta.sr.ht prefixes the service name to what it reads from
// api-meta.json, and authn.RepoScope is what a presented token is checked
// against. A drift would let a user mint a token meta calls valid and the clone
// path does not honour, which is a support ticket rather than an error.
func TestTheAdvertisedScopeIsTheEnforcedOne(t *testing.T) {
	assert.Equal(t, authn.RepoScope, serviceName+"/"+repoScopeName)
}

// The wiring, not the package: ecore's apimeta owns the never-null rule, and
// this asserts dolt.sr.ht actually declares the grant it enforces rather than
// serving an empty list that would leave meta with no checkbox to offer.
func TestAPIMetaAdvertisesTheRepoScope(t *testing.T) {
	rec := httptest.NewRecorder()
	apimeta.Handler(repoScopeName).ServeHTTP(rec, httptest.NewRequest(http.MethodGet, apimeta.Path, nil))

	require.Equal(t, http.StatusOK, rec.Code)

	var got apimeta.Meta
	require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &got))
	assert.Equal(t, []string{"repos"}, got.Scopes)
	assert.NotContains(t, rec.Body.String(), "null")
}