fix(permission): guard empty-origin query and resolve merge dupes
- commit
- c75e65dfbc06e451116925414f59c22067b521c3
- author
- brice · · 2026-02-08 12:36 UTC
- parent
- f14455f
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +20 -35
M cmd/dumber/main.go +2 -35
| @@ -507,41 +507,6 @@ func buildUIDependencies( | |||
| 507 | 507 | startupCrashReports []string, | |
| 508 | 508 | ) *ui.Dependencies { | |
| 509 | 509 | return &ui.Dependencies{ | |
| 510 | - | Ctx: ctx, | |
| 511 | - | Config: cfg, | |
| 512 | - | InitialURL: initialURL, | |
| 513 | - | RestoreSessionID: restoreSessionID, | |
| 514 | - | Theme: themeManager, | |
| 515 | - | ColorResolver: colorResolver, | |
| 516 | - | AdwaitaDetector: adwaitaDetector, | |
| 517 | - | XDG: xdg.New(), | |
| 518 | - | WebContext: stack.Context, | |
| 519 | - | Pool: stack.Pool, | |
| 520 | - | Settings: stack.Settings, | |
| 521 | - | Injector: stack.Injector, | |
| 522 | - | MessageRouter: stack.MessageRouter, | |
| 523 | - | FilterManager: stack.FilterManager, | |
| 524 | - | HistoryRepo: repos.history, | |
| 525 | - | FavoriteRepo: repos.favorite, | |
| 526 | - | ZoomRepo: repos.zoom, | |
| 527 | - | PermissionRepo: repos.permission, | |
| 528 | - | TabsUC: uc.tabs, | |
| 529 | - | PanesUC: uc.panes, | |
| 530 | - | HistoryUC: uc.history, | |
| 531 | - | FavoritesUC: uc.favorites, | |
| 532 | - | ZoomUC: uc.zoom, | |
| 533 | - | PermissionUC: uc.permission, | |
| 534 | - | NavigateUC: uc.navigate, | |
| 535 | - | CopyURLUC: uc.copyURL, | |
| 536 | - | Clipboard: uc.clipboard, | |
| 537 | - | FaviconService: uc.favicon, | |
| 538 | - | IdleInhibitor: idleInhibitor, | |
| 539 | - | SessionRepo: repos.session, | |
| 540 | - | SessionStateRepo: repos.sessionState, | |
| 541 | - | CurrentSessionID: currentSessionID, | |
| 542 | - | SnapshotUC: uc.snapshot, | |
| 543 | - | CheckUpdateUC: uc.checkUpdate, | |
| 544 | - | ApplyUpdateUC: uc.applyUpdate, | |
| 545 | 510 | Ctx: ctx, | |
| 546 | 511 | Config: cfg, | |
| 547 | 512 | InitialURL: initialURL, | |
| @@ -560,11 +525,13 @@ func buildUIDependencies( | |||
| 560 | 525 | HistoryRepo: repos.history, | |
| 561 | 526 | FavoriteRepo: repos.favorite, | |
| 562 | 527 | ZoomRepo: repos.zoom, | |
| 528 | + | PermissionRepo: repos.permission, | |
| 563 | 529 | TabsUC: uc.tabs, | |
| 564 | 530 | PanesUC: uc.panes, | |
| 565 | 531 | HistoryUC: uc.history, | |
| 566 | 532 | FavoritesUC: uc.favorites, | |
| 567 | 533 | ZoomUC: uc.zoom, | |
| 534 | + | PermissionUC: uc.permission, | |
| 568 | 535 | NavigateUC: uc.navigate, | |
| 569 | 536 | CopyURLUC: uc.copyURL, | |
| 570 | 537 | Clipboard: uc.clipboard, | |
| @@ -507,41 +507,6 @@ func buildUIDependencies( | |||||
| 507 | startupCrashReports []string, | 507 | startupCrashReports []string, | ||
| 508 | ) *ui.Dependencies { | 508 | ) *ui.Dependencies { | ||
| 509 | return &ui.Dependencies{ | 509 | return &ui.Dependencies{ | ||
| 510 | - | Ctx: ctx, | |||
| 511 | - | Config: cfg, | |||
| 512 | - | InitialURL: initialURL, | |||
| 513 | - | RestoreSessionID: restoreSessionID, | |||
| 514 | - | Theme: themeManager, | |||
| 515 | - | ColorResolver: colorResolver, | |||
| 516 | - | AdwaitaDetector: adwaitaDetector, | |||
| 517 | - | XDG: xdg.New(), | |||
| 518 | - | WebContext: stack.Context, | |||
| 519 | - | Pool: stack.Pool, | |||
| 520 | - | Settings: stack.Settings, | |||
| 521 | - | Injector: stack.Injector, | |||
| 522 | - | MessageRouter: stack.MessageRouter, | |||
| 523 | - | FilterManager: stack.FilterManager, | |||
| 524 | - | HistoryRepo: repos.history, | |||
| 525 | - | FavoriteRepo: repos.favorite, | |||
| 526 | - | ZoomRepo: repos.zoom, | |||
| 527 | - | PermissionRepo: repos.permission, | |||
| 528 | - | TabsUC: uc.tabs, | |||
| 529 | - | PanesUC: uc.panes, | |||
| 530 | - | HistoryUC: uc.history, | |||
| 531 | - | FavoritesUC: uc.favorites, | |||
| 532 | - | ZoomUC: uc.zoom, | |||
| 533 | - | PermissionUC: uc.permission, | |||
| 534 | - | NavigateUC: uc.navigate, | |||
| 535 | - | CopyURLUC: uc.copyURL, | |||
| 536 | - | Clipboard: uc.clipboard, | |||
| 537 | - | FaviconService: uc.favicon, | |||
| 538 | - | IdleInhibitor: idleInhibitor, | |||
| 539 | - | SessionRepo: repos.session, | |||
| 540 | - | SessionStateRepo: repos.sessionState, | |||
| 541 | - | CurrentSessionID: currentSessionID, | |||
| 542 | - | SnapshotUC: uc.snapshot, | |||
| 543 | - | CheckUpdateUC: uc.checkUpdate, | |||
| 544 | - | ApplyUpdateUC: uc.applyUpdate, | |||
| 545 | Ctx: ctx, | 510 | Ctx: ctx, | ||
| 546 | Config: cfg, | 511 | Config: cfg, | ||
| 547 | InitialURL: initialURL, | 512 | InitialURL: initialURL, | ||
| @@ -560,11 +525,13 @@ func buildUIDependencies( | |||||
| 560 | HistoryRepo: repos.history, | 525 | HistoryRepo: repos.history, | ||
| 561 | FavoriteRepo: repos.favorite, | 526 | FavoriteRepo: repos.favorite, | ||
| 562 | ZoomRepo: repos.zoom, | 527 | ZoomRepo: repos.zoom, | ||
| 528 | + | PermissionRepo: repos.permission, | |||
| 563 | TabsUC: uc.tabs, | 529 | TabsUC: uc.tabs, | ||
| 564 | PanesUC: uc.panes, | 530 | PanesUC: uc.panes, | ||
| 565 | HistoryUC: uc.history, | 531 | HistoryUC: uc.history, | ||
| 566 | FavoritesUC: uc.favorites, | 532 | FavoritesUC: uc.favorites, | ||
| 567 | ZoomUC: uc.zoom, | 533 | ZoomUC: uc.zoom, | ||
| 534 | + | PermissionUC: uc.permission, | |||
| 568 | NavigateUC: uc.navigate, | 535 | NavigateUC: uc.navigate, | ||
| 569 | CopyURLUC: uc.copyURL, | 536 | CopyURLUC: uc.copyURL, | ||
| 570 | Clipboard: uc.clipboard, | 537 | Clipboard: uc.clipboard, | ||
M internal/application/usecase/handle_permission.go +5 -0
| @@ -151,6 +151,11 @@ func (uc *HandlePermissionUseCase) QueryPermissionState( | |||
| 151 | 151 | Str("type", string(permType)). | |
| 152 | 152 | Logger() | |
| 153 | 153 | ||
| 154 | + | if origin == "" { | |
| 155 | + | log.Warn().Msg("query: empty origin, returning prompt") | |
| 156 | + | return entity.PermissionPrompt | |
| 157 | + | } | |
| 158 | + | ||
| 154 | 159 | // Check stored permission first (including manual overrides on auto-allow types). | |
| 155 | 160 | record, err := uc.permRepo.Get(ctx, origin, permType) | |
| 156 | 161 | if err != nil { | |
| @@ -151,6 +151,11 @@ func (uc *HandlePermissionUseCase) QueryPermissionState( | |||||
| 151 | Str("type", string(permType)). | 151 | Str("type", string(permType)). | ||
| 152 | Logger() | 152 | Logger() | ||
| 153 | 153 | ||||
| 154 | + | if origin == "" { | |||
| 155 | + | log.Warn().Msg("query: empty origin, returning prompt") | |||
| 156 | + | return entity.PermissionPrompt | |||
| 157 | + | } | |||
| 158 | + | ||||
| 154 | // Check stored permission first (including manual overrides on auto-allow types). | 159 | // Check stored permission first (including manual overrides on auto-allow types). | ||
| 155 | record, err := uc.permRepo.Get(ctx, origin, permType) | 160 | record, err := uc.permRepo.Get(ctx, origin, permType) | ||
| 156 | if err != nil { | 161 | if err != nil { | ||
M internal/application/usecase/handle_permission_test.go +13 -0
| @@ -365,6 +365,19 @@ func TestHandlePermissionUseCase_QueryPermissionState_NoRecord(t *testing.T) { | |||
| 365 | 365 | assert.Equal(t, entity.PermissionPrompt, state, "no record should return prompt") | |
| 366 | 366 | } | |
| 367 | 367 | ||
| 368 | + | func TestHandlePermissionUseCase_QueryPermissionState_EmptyOriginReturnsPrompt(t *testing.T) { | |
| 369 | + | ctx := testContext() | |
| 370 | + | permRepo := repomocks.NewMockPermissionRepository(t) | |
| 371 | + | dialog := portmocks.NewMockPermissionDialogPresenter(t) | |
| 372 | + | ||
| 373 | + | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | |
| 374 | + | ||
| 375 | + | state := uc.QueryPermissionState(ctx, "", entity.PermissionTypeDisplay) | |
| 376 | + | ||
| 377 | + | assert.Equal(t, entity.PermissionPrompt, state, "empty origin should return prompt") | |
| 378 | + | permRepo.AssertNotCalled(t, "Get") | |
| 379 | + | } | |
| 380 | + | ||
| 368 | 381 | func TestHandlePermissionUseCase_NonPersistableNotSaved(t *testing.T) { | |
| 369 | 382 | ctx := testContext() | |
| 370 | 383 | permRepo := repomocks.NewMockPermissionRepository(t) | |
| @@ -365,6 +365,19 @@ func TestHandlePermissionUseCase_QueryPermissionState_NoRecord(t *testing.T) { | |||||
| 365 | assert.Equal(t, entity.PermissionPrompt, state, "no record should return prompt") | 365 | assert.Equal(t, entity.PermissionPrompt, state, "no record should return prompt") | ||
| 366 | } | 366 | } | ||
| 367 | 367 | ||||
| 368 | + | func TestHandlePermissionUseCase_QueryPermissionState_EmptyOriginReturnsPrompt(t *testing.T) { | |||
| 369 | + | ctx := testContext() | |||
| 370 | + | permRepo := repomocks.NewMockPermissionRepository(t) | |||
| 371 | + | dialog := portmocks.NewMockPermissionDialogPresenter(t) | |||
| 372 | + | ||||
| 373 | + | uc := usecase.NewHandlePermissionUseCase(permRepo, dialog, permissionLoggerFromContext) | |||
| 374 | + | ||||
| 375 | + | state := uc.QueryPermissionState(ctx, "", entity.PermissionTypeDisplay) | |||
| 376 | + | ||||
| 377 | + | assert.Equal(t, entity.PermissionPrompt, state, "empty origin should return prompt") | |||
| 378 | + | permRepo.AssertNotCalled(t, "Get") | |||
| 379 | + | } | |||
| 380 | + | ||||
| 368 | func TestHandlePermissionUseCase_NonPersistableNotSaved(t *testing.T) { | 381 | func TestHandlePermissionUseCase_NonPersistableNotSaved(t *testing.T) { | ||
| 369 | ctx := testContext() | 382 | ctx := testContext() | ||
| 370 | permRepo := repomocks.NewMockPermissionRepository(t) | 383 | permRepo := repomocks.NewMockPermissionRepository(t) | ||