@@ -64,13 +64,6 @@ func TestOAuth2ProviderApps(t *testing.T) {
6464CallbackURL :"http://localhost:3000" ,
6565},
6666},
67- {
68- name :"NameTaken" ,
69- req : codersdk.PostOAuth2ProviderAppRequest {
70- Name :"taken" ,
71- CallbackURL :"http://localhost:3000" ,
72- },
73- },
7467{
7568name :"URLMissing" ,
7669req : codersdk.PostOAuth2ProviderAppRequest {
@@ -135,17 +128,8 @@ func TestOAuth2ProviderApps(t *testing.T) {
135128},
136129}
137130
138- // Generate an application for testing name conflicts.
139- req := codersdk.PostOAuth2ProviderAppRequest {
140- Name :"taken" ,
141- CallbackURL :"http://coder.com" ,
142- }
143- //nolint:gocritic // OAauth2 app management requires owner permission.
144- _ ,err := client .PostOAuth2ProviderApp (ctx ,req )
145- require .NoError (t ,err )
146-
147131// Generate an application for testing PUTs.
148- req = codersdk.PostOAuth2ProviderAppRequest {
132+ req : = codersdk.PostOAuth2ProviderAppRequest {
149133Name :fmt .Sprintf ("quark-%d" ,time .Now ().UnixNano ()% 1000000 ),
150134CallbackURL :"http://coder.com" ,
151135}
@@ -271,6 +255,65 @@ func TestOAuth2ProviderApps(t *testing.T) {
271255require .NoError (t ,err )
272256require .Len (t ,apps ,0 )
273257})
258+
259+ t .Run ("DuplicateNames" ,func (t * testing.T ) {
260+ t .Parallel ()
261+ client := coderdtest .New (t ,nil )
262+ _ = coderdtest .CreateFirstUser (t ,client )
263+ ctx := testutil .Context (t ,testutil .WaitLong )
264+
265+ // Create multiple OAuth2 apps with the same name to verify RFC 7591 compliance
266+ // RFC 7591 allows multiple apps to have the same name
267+ appName := fmt .Sprintf ("duplicate-name-%d" ,time .Now ().UnixNano ()% 1000000 )
268+
269+ // Create first app
270+ //nolint:gocritic // OAuth2 app management requires owner permission.
271+ app1 ,err := client .PostOAuth2ProviderApp (ctx , codersdk.PostOAuth2ProviderAppRequest {
272+ Name :appName ,
273+ CallbackURL :"http://localhost:3001" ,
274+ })
275+ require .NoError (t ,err )
276+ require .Equal (t ,appName ,app1 .Name )
277+
278+ // Create second app with the same name
279+ //nolint:gocritic // OAuth2 app management requires owner permission.
280+ app2 ,err := client .PostOAuth2ProviderApp (ctx , codersdk.PostOAuth2ProviderAppRequest {
281+ Name :appName ,
282+ CallbackURL :"http://localhost:3002" ,
283+ })
284+ require .NoError (t ,err )
285+ require .Equal (t ,appName ,app2 .Name )
286+
287+ // Create third app with the same name
288+ //nolint:gocritic // OAuth2 app management requires owner permission.
289+ app3 ,err := client .PostOAuth2ProviderApp (ctx , codersdk.PostOAuth2ProviderAppRequest {
290+ Name :appName ,
291+ CallbackURL :"http://localhost:3003" ,
292+ })
293+ require .NoError (t ,err )
294+ require .Equal (t ,appName ,app3 .Name )
295+
296+ // Verify all apps have different IDs but same name
297+ require .NotEqual (t ,app1 .ID ,app2 .ID )
298+ require .NotEqual (t ,app1 .ID ,app3 .ID )
299+ require .NotEqual (t ,app2 .ID ,app3 .ID )
300+ require .Equal (t ,app1 .Name ,app2 .Name )
301+ require .Equal (t ,app1 .Name ,app3 .Name )
302+
303+ // Verify all apps can be retrieved and have the same name
304+ //nolint:gocritic // OAuth2 app management requires owner permission.
305+ apps ,err := client .OAuth2ProviderApps (ctx , codersdk.OAuth2ProviderAppFilter {})
306+ require .NoError (t ,err )
307+
308+ // Count apps with our duplicate name
309+ duplicateNameCount := 0
310+ for _ ,app := range apps {
311+ if app .Name == appName {
312+ duplicateNameCount ++
313+ }
314+ }
315+ require .Equal (t ,3 ,duplicateNameCount ,"Should have exactly 3 apps with the duplicate name" )
316+ })
274317}
275318
276319func TestOAuth2ProviderAppSecrets (t * testing.T ) {