(t *testing.T)
| 751 | {"present bare", []string{"ducklake", "cache_httpfs"}, true}, |
| 752 | {"present with source", []string{"ducklake", "cache_httpfs FROM community"}, true}, |
| 753 | {"absent", []string{"ducklake", "httpfs"}, false}, |
| 754 | {"empty list", []string{}, false}, |
| 755 | {"nil list", nil, false}, |
| 756 | {"similar name", []string{"not_cache_httpfs"}, false}, |
| 757 | {"substring match", []string{"cache_httpfs_v2 FROM community"}, false}, |
| 758 | } |
| 759 | |
| 760 | for _, tt := range tests { |
| 761 | t.Run(tt.name, func(t *testing.T) { |
| 762 | got := hasCacheHTTPFS(tt.extensions) |
| 763 | if got != tt.want { |
| 764 | t.Errorf("hasCacheHTTPFS(%v) = %v, want %v", tt.extensions, got, tt.want) |
| 765 | } |
| 766 | }) |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | func TestOpenBaseDBFilePersistenceRejectsPathTraversal(t *testing.T) { |
| 771 | dataDir := t.TempDir() |
| 772 | cfg := Config{ |
| 773 | FilePersistence: true, |
| 774 | DataDir: dataDir, |
| 775 | } |
| 776 | |
| 777 | cases := []struct { |
| 778 | name string |
| 779 | username string |
| 780 | }{ |
| 781 | {"parent directory", "../etc/evil"}, |
| 782 | {"slash in name", "foo/bar"}, |
| 783 | {"backslash dot-dot", "..\\windows"}, |
| 784 | {"dot-dot between names", "alice/../bob"}, |
| 785 | } |
| 786 | |
| 787 | for _, tc := range cases { |
| 788 | t.Run(tc.name, func(t *testing.T) { |
| 789 | db, err := openBaseDB(cfg, tc.username) |
| 790 | if err == nil { |
| 791 | _ = db.Close() |
| 792 | t.Fatalf("expected error for username %q, got nil", tc.username) |
| 793 | } |
| 794 | if !strings.Contains(err.Error(), "invalid username for file persistence") { |
| 795 | t.Fatalf("unexpected error: %v", err) |
| 796 | } |
| 797 | }) |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | func TestOpenBaseDBCreatesDataDir(t *testing.T) { |
| 802 | base := t.TempDir() |
| 803 | nested := filepath.Join(base, "deep", "nested", "dir") |
| 804 | |
| 805 | cfg := Config{ |
| 806 | FilePersistence: true, |
| 807 | DataDir: nested, |
| 808 | } |
| 809 | db, err := openBaseDB(cfg, "testuser") |
| 810 | if err != nil { |
nothing calls this directly
no test coverage detected