Add a secure repository Prompts review surface and prompt metadata API
Hop-State: A_06FN6MRSHG4B64ZV13086G8 Hop-Proposal: R_06FN6MQDE14FFNR65H1D28G Hop-Task: T_06FN6J8ECE1Z9XQ5PQ3Z3D8 Hop-Attempt: AT_06FN6J8ECC1SC794JMZ0TF8
This commit is contained in:
@@ -42,3 +42,41 @@ func TestRepositoryRequiresToken(t *testing.T) {
|
||||
t.Fatalf("error = %v, want %v", err, ErrTokenNotConfigured)
|
||||
}
|
||||
}
|
||||
|
||||
func TestViewerCanReadRepositoryForwardsSessionCookie(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/repos/hop/private" {
|
||||
t.Fatalf("path = %q", r.URL.Path)
|
||||
}
|
||||
if got := r.Header.Get("Cookie"); got != "i_like_gitea=session" {
|
||||
t.Fatalf("cookie = %q", got)
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client, err := NewClient(server.URL, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
allowed, err := client.ViewerCanReadRepository(context.Background(), "i_like_gitea=session", "hop", "private")
|
||||
if err != nil || !allowed {
|
||||
t.Fatalf("allowed = %t, err = %v", allowed, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestViewerCannotReadMissingRepository(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client, err := NewClient(server.URL, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
allowed, err := client.ViewerCanReadRepository(context.Background(), "i_like_gitea=session", "hop", "missing")
|
||||
if err != nil || allowed {
|
||||
t.Fatalf("allowed = %t, err = %v", allowed, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user