Skip to content

Commit 14a2d9e

Browse files
committed
test: add unit tests for chromium and firefox finder on Windows
1 parent 8b37ad5 commit 14a2d9e

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

profile/finder_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package profile
22

33
import (
4+
"os"
45
"path/filepath"
56
"runtime"
67
"testing"
@@ -58,6 +59,58 @@ func TestProfileFinder_FirefoxMacOS(t *testing.T) {
5859
}
5960
}
6061

62+
func TestNewManager_ChromiumWindows(t *testing.T) {
63+
if runtime.GOOS != "windows" {
64+
t.Skip("skipping test on non-windows system")
65+
}
66+
userProfile := os.Getenv("USERPROFILE")
67+
rootPath := filepath.Join(userProfile, `AppData\Local\Google\Chrome\User Data`)
68+
paths, err := filepath.Glob(rootPath)
69+
70+
assert.NoError(t, err)
71+
if len(paths) == 0 {
72+
t.Skip("no chrome profile found")
73+
}
74+
browserType := types2.ChromiumType
75+
dataTypes := types2.AllDataTypes
76+
finder := NewFinder()
77+
profiles, err := finder.FindProfiles(rootPath, browserType, dataTypes)
78+
assert.NoError(t, err)
79+
assert.NotNil(t, profiles)
80+
for name, profile := range profiles {
81+
for k, v := range profile.DataFilePath {
82+
t.Logf("name: %s, datatype: %s, datapath: %s", name, k.String(), v)
83+
}
84+
t.Log(name, profile.MasterKeyPath)
85+
}
86+
}
87+
88+
func TestProfileFinder_FirefoxWindows(t *testing.T) {
89+
if runtime.GOOS != "windows" {
90+
t.Skip("skipping test on non-windows system")
91+
}
92+
userProfile := os.Getenv("USERPROFILE")
93+
rootPath := filepath.Join(userProfile, `AppData\Roaming\Mozilla\Firefox\Profiles`)
94+
paths, err := filepath.Glob(rootPath)
95+
96+
assert.NoError(t, err)
97+
if len(paths) == 0 {
98+
t.Skip("no firefox profile found")
99+
}
100+
browserType := types2.FirefoxType
101+
dataTypes := types2.AllDataTypes
102+
finder := NewFinder()
103+
profiles, err := finder.FindProfiles(rootPath, browserType, dataTypes)
104+
assert.NoError(t, err)
105+
assert.NotNil(t, profiles)
106+
for name, profile := range profiles {
107+
for k, v := range profile.DataFilePath {
108+
t.Logf("name: %s, datatype: %s, value: %s", name, k.String(), v)
109+
}
110+
t.Log(name, profile.MasterKeyPath)
111+
}
112+
}
113+
61114
func Test_extractProfileNameFromPath(t *testing.T) {
62115
testCases := []struct {
63116
name string

types/types_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package types
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67
"strconv"
78
"testing"
89

@@ -30,7 +31,7 @@ func TestDataType_TempFilename(t *testing.T) {
3031
}{
3132
{ChromiumKey, "Local State"},
3233
{ChromiumPassword, "Login Data"},
33-
{ChromiumLocalStorage, "Local Storage/leveldb"},
34+
{ChromiumLocalStorage, filepath.Join("Local Storage", "leveldb")},
3435
{FirefoxSessionStorage, "unsupported item"},
3536
{FirefoxLocalStorage, "webappsstore.sqlite"},
3637
{YandexPassword, "Ya Passman Data"},

0 commit comments

Comments
 (0)