Enable CLI language-aware editing and reuse OIDC authentication
This commit is contained in:
1 parent
5821254535
commit
93f4ecb8f4
11 files changed
+264
-84
No files matched your search
@@ -17,7 +17,14 @@ func TestRemoteCLIHTTPIntegration(t *testing.T) {
|
||||
if _, err := exec.LookPath("python3"); err != nil {
|
||||
t.Skip("python3 not installed")
|
||||
}
|
||||
s, _, _, _ := editorFixture(t)
|
||||
s, _, domain, _ := editorFixture(t)
|
||||
object, err := s.store.CreatePageAtPathInDomain(domain, "/ja-only")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.store.SaveRevisionForLanguage(object, "<h1>日本語のページ</h1><p>{{children}}</p>", "", "ja"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.mux.HandleFunc("/_/auth/", s.handleAuth)
|
||||
s.mux.HandleFunc("/v/raw/", s.handleRawView)
|
||||
s.mux.HandleFunc("/_/api/v1/path-picker", s.handlePathPickerAPI)
|
||||
@@ -36,6 +43,39 @@ func TestRemoteCLIHTTPIntegration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteCLILanguageForkRequiresWritePermission(t *testing.T) {
|
||||
s, token, domain, object := editorFixture(t)
|
||||
principal := s.mustCLIPrincipal(t, domain, token)
|
||||
if err := s.store.SetPrincipalState(domain, principal, "readonly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Changing account state revokes old sessions. Use a newly authenticated
|
||||
// readonly session so this exercises write authorization, not expiration.
|
||||
token, err := s.store.CreateAuthSession(domain, principal)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body, err := json.Marshal(map[string]any{
|
||||
"object_uuid": object, "body": "<h1>New language</h1>", "lang": "ja",
|
||||
"content_type": "text/html", "base_revision_uuid": "", "editor_principal_uuid": principal,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := httptest.NewRequest("POST", "http://localhost/_/api/v1/revisions/save", bytes.NewReader(body))
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
r.Header.Set("Content-Type", "application/json")
|
||||
w := httptest.NewRecorder()
|
||||
s.withAuthorization(s.mux).ServeHTTP(w, r)
|
||||
if w.Code != http.StatusForbidden {
|
||||
t.Fatalf("readonly language fork: %d %s", w.Code, w.Body.String())
|
||||
}
|
||||
revision, err := s.store.GetRevisionMetadataForExactLanguage(object, "ja")
|
||||
if err != nil || revision.UUID != "" {
|
||||
t.Fatalf("denied language fork persisted: %s %v", revision.UUID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteCLIOIDCIntegration(t *testing.T) {
|
||||
if _, err := exec.LookPath("python3"); err != nil {
|
||||
t.Skip("python3 not installed")
|
||||
|
||||
Reference in new issue
Block a user