feat!: remove gitea command in favor of gt
Gitea login is handled by gt directly. The OAuth relay polling that atproto shares moves to internal/relay.
This commit is contained in:
1 parent
a1cfcc1de7
commit
8bc017ca72
6 files changed
+143
-541
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package relay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPoll(t *testing.T) {
|
||||
var polls atomic.Int32
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/oauth/poll" || r.URL.Query().Get("state") != "st-1" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if polls.Add(1) < 2 {
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"status": "pending"})
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ready", "code": "code-abc"})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
code, err := Poll(ctx, srv.Client(), srv.URL, "st-1", 10*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatalf("Poll: %v", err)
|
||||
}
|
||||
if code != "code-abc" {
|
||||
t.Fatalf("code = %q", code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedirectURI(t *testing.T) {
|
||||
if got := RedirectURI("https://x.example/"); got != "https://x.example/oauth/callback" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user