@@ -74,62 +74,4 @@ func TestTerraformRegistryHandler(t *testing.T) {
7474
7575 assert .Equal (t , "" , request .Header .Get ("Authorization" ), "should be empty" )
7676 })
77-
78- t .Run ("multiple credentials on same host with different URL paths" , func (t * testing.T ) {
79- credentials := config.Credentials {
80- config.Credential {"type" : "terraform_registry" , "url" : "https://terraform.example.com/org1" , "token" : "token-org1" },
81- config.Credential {"type" : "terraform_registry" , "url" : "https://terraform.example.com/org2" , "token" : "token-org2" },
82- }
83- handler := NewTerraformRegistryHandler (credentials )
84-
85- // Request to org1 path should use org1 token
86- req1 := handleRequestAndClose (handler , httptest .NewRequest ("GET" , "https://terraform.example.com/org1/v1/providers/foo" , nil ), nil )
87- assert .Equal (t , "Bearer token-org1" , req1 .Header .Get ("Authorization" ), "should use org1 token" )
88-
89- // Request to org2 path should use org2 token
90- req2 := handleRequestAndClose (handler , httptest .NewRequest ("GET" , "https://terraform.example.com/org2/v1/providers/bar" , nil ), nil )
91- assert .Equal (t , "Bearer token-org2" , req2 .Header .Get ("Authorization" ), "should use org2 token" )
92-
93- // Request to unmatched path should not be authenticated
94- req3 := handleRequestAndClose (handler , httptest .NewRequest ("GET" , "https://terraform.example.com/org3/v1/providers/baz" , nil ), nil )
95- assert .Equal (t , "" , req3 .Header .Get ("Authorization" ), "should not be authenticated" )
96- })
97-
98- t .Run ("skips credentials with empty token" , func (t * testing.T ) {
99- credentials := config.Credentials {
100- config.Credential {"type" : "terraform_registry" , "host" : "terraform.example.org" , "token" : "" },
101- }
102- handler := NewTerraformRegistryHandler (credentials )
103- assert .Equal (t , 0 , len (handler .credentials ), "should skip credential with empty token" )
104- })
105-
106- t .Run ("skips credentials with empty host and url" , func (t * testing.T ) {
107- credentials := config.Credentials {
108- config.Credential {"type" : "terraform_registry" , "token" : "some-token" },
109- }
110- handler := NewTerraformRegistryHandler (credentials )
111- assert .Equal (t , 0 , len (handler .credentials ), "should skip credential with empty host and url" )
112- })
113-
114- t .Run ("path boundary: /org should not match /org1" , func (t * testing.T ) {
115- // Credentials are sorted longest-path-first to ensure /org1 matches before /org
116- credentials := config.Credentials {
117- config.Credential {"type" : "terraform_registry" , "url" : "https://terraform.example.com/org" , "token" : "token-org" },
118- config.Credential {"type" : "terraform_registry" , "url" : "https://terraform.example.com/org1" , "token" : "token-org1" },
119- }
120- handler := NewTerraformRegistryHandler (credentials )
121-
122- assert .Equal (t , "https://terraform.example.com/org1" , handler .credentials [0 ].url , "longer path should be first" )
123- assert .Equal (t , "https://terraform.example.com/org" , handler .credentials [1 ].url , "shorter path should be second" )
124-
125- req1 := handleRequestAndClose (handler , httptest .NewRequest ("GET" , "https://terraform.example.com/org1/v1/providers/foo" , nil ), nil )
126- assert .Equal (t , "Bearer token-org1" , req1 .Header .Get ("Authorization" ), "/org1 path should use org1 token" )
127-
128- req2 := handleRequestAndClose (handler , httptest .NewRequest ("GET" , "https://terraform.example.com/org/v1/providers/bar" , nil ), nil )
129- assert .Equal (t , "Bearer token-org" , req2 .Header .Get ("Authorization" ), "/org path should use org token" )
130-
131- // Request to /org123 should NOT match /org1 or /org (path boundary check)
132- req3 := handleRequestAndClose (handler , httptest .NewRequest ("GET" , "https://terraform.example.com/org123/v1/providers/baz" , nil ), nil )
133- assert .Equal (t , "" , req3 .Header .Get ("Authorization" ), "/org123 should not match /org or /org1" )
134- })
13577}
0 commit comments