Go boilerplate library for building atproto apps
atproto go
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 95 lines 2.2 kB view raw
1package atp 2 3import ( 4 "testing" 5 6 "github.com/bluesky-social/indigo/atproto/auth/oauth" 7) 8 9func TestNewOAuthApp(t *testing.T) { 10 tests := []struct { 11 name string 12 config OAuthConfig 13 }{ 14 { 15 name: "localhost IP", 16 config: OAuthConfig{ 17 ClientID: "", 18 RedirectURI: "http://127.0.0.1:12345/callback", 19 Scopes: []string{"atproto"}, 20 Store: oauth.NewMemStore(), 21 }, 22 }, 23 { 24 name: "localhost prefix", 25 config: OAuthConfig{ 26 ClientID: "http://localhost:8080", 27 RedirectURI: "http://localhost:8080/oauth/callback", 28 Scopes: []string{"atproto"}, 29 Store: oauth.NewMemStore(), 30 }, 31 }, 32 { 33 name: "public client", 34 config: OAuthConfig{ 35 ClientID: "https://example.com/client-metadata.json", 36 RedirectURI: "https://example.com/oauth/callback", 37 Scopes: ScopesForCollections("x.y.bean"), 38 Store: oauth.NewMemStore(), 39 }, 40 }, 41 { 42 name: "nil store", 43 config: OAuthConfig{ 44 RedirectURI: "http://127.0.0.1:12345/callback", 45 Scopes: []string{"atproto"}, 46 }, 47 }, 48 } 49 for _, tc := range tests { 50 t.Run(tc.name, func(t *testing.T) { 51 app, err := NewOAuthApp(tc.config) 52 if err != nil { 53 t.Fatal(err) 54 } 55 if app == nil { 56 t.Fatal("expected non-nil app") 57 } 58 }) 59 } 60} 61 62func TestOAuthApp_ClientMetadata(t *testing.T) { 63 app, _ := NewOAuthApp(OAuthConfig{ 64 RedirectURI: "http://127.0.0.1:12345/callback", 65 Scopes: []string{"atproto"}, 66 }) 67 meta := app.ClientMetadata() 68 if meta.ClientID == "" { 69 t.Fatal("expected non-empty client ID in metadata") 70 } 71} 72 73func TestOAuthApp_ClientMetadata_AppName(t *testing.T) { 74 app, _ := NewOAuthApp(OAuthConfig{ 75 RedirectURI: "http://127.0.0.1:12345/callback", 76 Scopes: []string{"atproto"}, 77 AppName: "TestApp", 78 }) 79 meta := app.ClientMetadata() 80 if meta.ClientName == nil || *meta.ClientName != "TestApp" { 81 t.Fatal("expected AppName in metadata") 82 } 83} 84 85func TestOAuthApp_Store(t *testing.T) { 86 memStore := oauth.NewMemStore() 87 app, _ := NewOAuthApp(OAuthConfig{ 88 RedirectURI: "http://127.0.0.1:12345/callback", 89 Scopes: []string{"atproto"}, 90 Store: memStore, 91 }) 92 if app.Store() == nil { 93 t.Fatal("expected non-nil store") 94 } 95}