Upload images to your PDS and get instant CDN URLs via images.blue
at main 119 lines 3.8 kB view raw
1package auth 2 3import ( 4 "testing" 5) 6 7func TestGetClientMetadata(t *testing.T) { 8 metadata := GetClientMetadata() 9 10 // Verify required fields are populated 11 if metadata.ClientID == "" { 12 t.Error("ClientID should not be empty") 13 } 14 if metadata.ClientName == "" { 15 t.Error("ClientName should not be empty") 16 } 17 if metadata.ClientURI == "" { 18 t.Error("ClientURI should not be empty") 19 } 20 if len(metadata.RedirectURIs) == 0 { 21 t.Error("RedirectURIs should not be empty") 22 } 23 if len(metadata.GrantTypes) == 0 { 24 t.Error("GrantTypes should not be empty") 25 } 26 if metadata.Scope == "" { 27 t.Error("Scope should not be empty") 28 } 29 30 // Verify expected values from client-metadata.json 31 if metadata.ClientID != "https://blup.imgs.blue/oauth-client-metadata.json" { 32 t.Errorf("ClientID = %q, want %q", metadata.ClientID, "https://blup.imgs.blue/oauth-client-metadata.json") 33 } 34 if metadata.ClientName != "Blup" { 35 t.Errorf("ClientName = %q, want %q", metadata.ClientName, "Blup") 36 } 37 if metadata.ClientURI != "https://blup.imgs.blue" { 38 t.Errorf("ClientURI = %q, want %q", metadata.ClientURI, "https://blup.imgs.blue") 39 } 40 if metadata.RedirectURIs[0] != "https://blup.imgs.blue/oauth/callback" { 41 t.Errorf("RedirectURIs[0] = %q, want %q", metadata.RedirectURIs[0], "https://blup.imgs.blue/oauth/callback") 42 } 43 if !metadata.DpopBoundAccessTokens { 44 t.Error("DpopBoundAccessTokens should be true") 45 } 46 if metadata.TokenEndpointAuthMethod != "none" { 47 t.Errorf("TokenEndpointAuthMethod = %q, want %q", metadata.TokenEndpointAuthMethod, "none") 48 } 49 if metadata.ApplicationType != "native" { 50 t.Errorf("ApplicationType = %q, want %q", metadata.ApplicationType, "native") 51 } 52} 53 54func TestGetClientMetadataGrantTypes(t *testing.T) { 55 metadata := GetClientMetadata() 56 57 expectedGrantTypes := []string{"authorization_code", "refresh_token"} 58 if len(metadata.GrantTypes) != len(expectedGrantTypes) { 59 t.Fatalf("GrantTypes length = %d, want %d", len(metadata.GrantTypes), len(expectedGrantTypes)) 60 } 61 62 for i, gt := range expectedGrantTypes { 63 if metadata.GrantTypes[i] != gt { 64 t.Errorf("GrantTypes[%d] = %q, want %q", i, metadata.GrantTypes[i], gt) 65 } 66 } 67} 68 69func TestGetClientMetadataResponseTypes(t *testing.T) { 70 metadata := GetClientMetadata() 71 72 if len(metadata.ResponseTypes) != 1 { 73 t.Fatalf("ResponseTypes length = %d, want 1", len(metadata.ResponseTypes)) 74 } 75 if metadata.ResponseTypes[0] != "code" { 76 t.Errorf("ResponseTypes[0] = %q, want %q", metadata.ResponseTypes[0], "code") 77 } 78} 79 80func TestGetClientConfig(t *testing.T) { 81 config := GetClientConfig() 82 83 // Verify the config is built correctly 84 if config.ClientID == "" { 85 t.Error("ClientID should not be empty") 86 } 87 if config.CallbackURL == "" { 88 t.Error("CallbackURL should not be empty") 89 } 90 if len(config.Scopes) == 0 { 91 t.Error("Scopes should not be empty") 92 } 93 94 // Verify expected values 95 if config.ClientID != "https://blup.imgs.blue/oauth-client-metadata.json" { 96 t.Errorf("ClientID = %q, want %q", config.ClientID, "https://blup.imgs.blue/oauth-client-metadata.json") 97 } 98 if config.CallbackURL != "https://blup.imgs.blue/oauth/callback" { 99 t.Errorf("CallbackURL = %q, want %q", config.CallbackURL, "https://blup.imgs.blue/oauth/callback") 100 } 101} 102 103func TestGetClientConfigScopes(t *testing.T) { 104 config := GetClientConfig() 105 106 // Scope in metadata is "atproto repo:blue.imgs.blup.image blob:image/*" 107 // Should be split into 3 scopes 108 expectedScopes := []string{"atproto", "repo:blue.imgs.blup.image", "blob:image/*"} 109 110 if len(config.Scopes) != len(expectedScopes) { 111 t.Fatalf("Scopes length = %d, want %d; got %v", len(config.Scopes), len(expectedScopes), config.Scopes) 112 } 113 114 for i, scope := range expectedScopes { 115 if config.Scopes[i] != scope { 116 t.Errorf("Scopes[%d] = %q, want %q", i, config.Scopes[i], scope) 117 } 118 } 119}