github.com/supabase/cli@v1.168.1/internal/sso/list/list_test.go (about) 1 package list 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/supabase/cli/internal/testing/apitest" 9 "github.com/supabase/cli/internal/utils" 10 "gopkg.in/h2non/gock.v1" 11 ) 12 13 func TestSSOProvidersListCommand(t *testing.T) { 14 t.Run("lists all providers", func(t *testing.T) { 15 // Setup valid access token 16 token := apitest.RandomAccessToken(t) 17 t.Setenv("SUPABASE_ACCESS_TOKEN", string(token)) 18 19 // Flush pending mocks after test execution 20 defer gock.OffAll() 21 22 projectRef := "abcdefghijklmnopqrst" 23 24 gock.New(utils.DefaultApiHost). 25 Get("/v1/projects/" + projectRef + "/config/auth/sso/providers"). 26 Reply(200). 27 JSON(map[string]any{ 28 "items": []map[string]any{ 29 { 30 "id": "0b0d48f6-878b-4190-88d7-2ca33ed800bc", 31 "created_at": "2023-03-28T13:50:14.464Z", 32 "updated_at": "2023-03-28T13:50:14.464Z", 33 "saml": map[string]any{ 34 "id": "8682fcf4-4056-455c-bd93-f33295604929", 35 "metadata_url": "https://example.com", 36 "metadata_xml": "<?xml version=\"2.0\"?>", 37 "entity_id": "https://example.com", 38 "attribute_mapping": map[string]any{ 39 "keys": map[string]any{ 40 "a": map[string]any{ 41 "name": "xyz", 42 "names": []string{ 43 "x", 44 "y", 45 "z", 46 }, 47 "default": 3, 48 }, 49 }, 50 }, 51 "created_at": "2023-03-28T13:50:14.464Z", 52 "updated_at": "2023-03-28T13:50:14.464Z", 53 }, 54 "domains": []map[string]any{ 55 { 56 "id": "9484591c-a203-4500-bea7-d0aaa845e2f5", 57 "domain": "example.com", 58 "created_at": "2023-03-28T13:50:14.464Z", 59 "updated_at": "2023-03-28T13:50:14.464Z", 60 }, 61 }, 62 }, 63 }, 64 }) 65 66 // Run test 67 assert.NoError(t, Run(context.Background(), projectRef, utils.OutputPretty)) 68 // Validate api 69 assert.Empty(t, apitest.ListUnmatchedRequests()) 70 }) 71 72 t.Run("list providers with disabled SAML", func(t *testing.T) { 73 // Setup valid access token 74 token := apitest.RandomAccessToken(t) 75 t.Setenv("SUPABASE_ACCESS_TOKEN", string(token)) 76 77 // Flush pending mocks after test execution 78 defer gock.OffAll() 79 80 projectRef := "abcdefghijklmnopqrst" 81 82 gock.New(utils.DefaultApiHost). 83 Get("/v1/projects/" + projectRef + "/config/auth/sso/providers"). 84 Reply(404). 85 JSON(map[string]string{}) 86 87 err := Run(context.Background(), projectRef, utils.OutputPretty) 88 89 // Run test 90 assert.Error(t, err) 91 assert.Equal(t, err.Error(), "Looks like SAML 2.0 support is not enabled for this project. Please use the dashboard to enable it.") 92 93 // Validate api 94 assert.Empty(t, apitest.ListUnmatchedRequests()) 95 }) 96 }