Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/tpmctl/cmd/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func TestAdd(t *testing.T) {
}{
"Success": {},

"Fail_on_user_privilege": {admineUID: 1, wantErr: true},
"Fail_reading_input": {ttyReadError: true, wantErr: true},
"Fail_wrong_auth_mode": {wantErr: true},
"Fail_on_validating": {wantErr: true},
"Fail_on_adding": {wantErr: true},
"Error_on_user_privilege": {admineUID: 1, wantErr: true},
"Error_reading_input": {ttyReadError: true, wantErr: true},
"Error_wrong_auth_mode": {wantErr: true},
"Error_on_validating": {wantErr: true},
"Error_on_adding": {wantErr: true},
}
for _, command := range commands {
for name, tc := range tests {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tpmctl/cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func TestCheck(t *testing.T) {
"Success_even_with_invalid_recovery_key": {},
"Success_even_with_incorrect_recovery_key": {key: "incorrect"},

"Fail_reading_input": {ttyReadError: true, wantErr: true},
"Fail_checking_recovery_key": {wantErr: true},
"Error_reading_input": {ttyReadError: true, wantErr: true},
"Error_checking_recovery_key": {wantErr: true},
}

for name, tc := range tests {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tpmctl/cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCreateKey(t *testing.T) {

wantErr bool
}{
"Success_on_creting_recovery_key": {},
"Success_on_creating_recovery_key": {},

"Error_from_snapd_on_empty_name": {wantErr: true},
"Error_from_snapd_on_unique_name": {recoveryKeyName: "test-duplicate", wantErr: true},
Expand Down
24 changes: 12 additions & 12 deletions cmd/tpmctl/cmd/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func TestMountVolume(t *testing.T) {
}{
"Success on mounting volume": {},

"Error out when authRequestor fails": {ttyReadError: true, wantErr: true},
"Error out when mount fails": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantErr: true},
"Error out when volume is already mounted": {alreadyMountedErr: true, wantErr: true},
"Error out when device doesn't exists": {deviceStatError: true, wantErr: true},
"Error out when device is empty": {emptyDeviceError: true, wantErr: true},
"Error out when dir path is empty": {emptyDirError: true, wantErr: true},
"Error out when device is already in use by another tool": {deviceInUse: true, wantErr: true},
"Error_when_authRequestor_fails": {ttyReadError: true, wantErr: true},
"Error_when_mount_fails": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantErr: true},
"Error_when_volume_is_already_mounted": {alreadyMountedErr: true, wantErr: true},
"Error_when_device_does_not_exist": {deviceStatError: true, wantErr: true},
"Error_when_device_is_empty": {emptyDeviceError: true, wantErr: true},
"Error_when_dir_path_is_empty": {emptyDirError: true, wantErr: true},
"Error_when_device_is_already_in_use_by_another_tool": {deviceInUse: true, wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -142,8 +142,8 @@ func TestUnmountVolume(t *testing.T) {
}{
"Success on unmounting volume": {},

"Error out when unmount fails": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantErr: true},
"Error out when dir path is empty": {emptyDirError: true, wantErr: true},
"Error_when_unmount_fails": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantErr: true},
"Error_when_dir_path_is_empty": {emptyDirError: true, wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -209,9 +209,9 @@ func TestGetLuksKeyFromRecoveryKey(t *testing.T) {
"Success_getting_luks_key_with_hex_flag": {hexFlag: true},
"Success_getting_luks_key_with_escaped_flag": {escapedFlag: true},

"Fail_reading_input": {ttyReadError: true, wantErr: true},
"Fail_getting_luks_key": {recoveryKey: "invalid", wantErr: true},
"Fail_for_too_many_flags": {wantErr: true, hexFlag: true, escapedFlag: true},
"Error_reading_input": {ttyReadError: true, wantErr: true},
"Error_getting_luks_key": {recoveryKey: "invalid", wantErr: true},
"Error_for_too_many_flags": {wantErr: true, hexFlag: true, escapedFlag: true},
}

for name, tc := range tests {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tpmctl/cmd/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func TestRemove(t *testing.T) {
}{
"Success_on_removing": {},

"Fail_on_user_privilege": {admineUID: 1, wantErr: true},
"Fail_on_removing": {wantErr: true},
"Error_on_user_privilege": {admineUID: 1, wantErr: true},
"Error_on_removing": {wantErr: true},
}
for _, command := range commands {
for name, tc := range tests {
Expand Down
6 changes: 3 additions & 3 deletions cmd/tpmctl/cmd/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func TestReplace(t *testing.T) {
}{
"Success_on_replacing": {},

"Fail_reading_input": {ttyReadError: true, wantErr: true},
"Fail_on_validating": {wantErr: true},
"Fail_on_replacing": {wantErr: true},
"Error_reading_input": {ttyReadError: true, wantErr: true},
"Error_on_validating": {wantErr: true},
"Error_on_replacing": {wantErr: true},
}

for _, command := range commands {
Expand Down
8 changes: 4 additions & 4 deletions cmd/tpmctl/integrationtests/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func TestAdd(t *testing.T) {
}{
"Success": {},

"Fail_on_user_privilege": {nonRootUser: true, wantErr: true},
"Fail_wrong_auth_mode": {wantErr: true},
"Fail_on_validating": {wantErr: true},
"Fail_on_adding": {wantErr: true},
"Error_on_user_privilege": {nonRootUser: true, wantErr: true},
"Error_wrong_auth_mode": {wantErr: true},
"Error_on_validating": {wantErr: true},
"Error_on_adding": {wantErr: true},
}
for _, command := range commands {
for name, tc := range tests {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tpmctl/integrationtests/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCheck(t *testing.T) {
"Success_even_with_invalid_recovery_key": {},
"Success_even_with_incorrect_recovery_key": {key: "incorrect"},

"Fail_checking_recovery_key": {wantErr: true},
"Error_checking_recovery_key": {wantErr: true},
}

for name, tc := range tests {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tpmctl/integrationtests/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestCreateKey(t *testing.T) {

wantErr bool
}{
"Success_on_creting_recovery_key": {},
"Success_on_creating_recovery_key": {},

"Error_from_snapd_on_empty_name": {wantErr: true},
"Error_from_snapd_on_unique_name": {recoveryKeyName: "test-duplicate", wantErr: true},
Expand Down
19 changes: 10 additions & 9 deletions cmd/tpmctl/integrationtests/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ func TestMountVolume(t *testing.T) {
}{
"Success on mounting volume": {},

"Error out when mount fails": {mountErr: true, wantErr: true},
"Error out when volume is already mounted": {alreadyMountedErr: true, wantErr: true},
"Error out when device doesn't exists": {deviceStatError: true, wantErr: true},
"Error out when device is empty": {emptyDeviceError: true, wantErr: true},
"Error out when dir path is empty": {emptyDirError: true, wantErr: true}, "Error out when device is already in use by another tool": {deviceInUse: true, wantErr: true},
"Error_when_mount_fails": {mountErr: true, wantErr: true},
"Error_when_volume_is_already_mounted": {alreadyMountedErr: true, wantErr: true},
"Error_when_device_does_not_exist": {deviceStatError: true, wantErr: true},
"Error_when_device_is_empty": {emptyDeviceError: true, wantErr: true},
"Error_when_dir_path_is_empty": {emptyDirError: true, wantErr: true},
"Error_when_device_is_already_in_use_by_another_tool": {deviceInUse: true, wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -119,8 +120,8 @@ func TestUnmountVolume(t *testing.T) {
}{
"Success on unmounting volume": {},

"Error out when unmount fails": {unmountErr: true, wantErr: true},
"Error out when dir path is empty": {emptyDirError: true, wantErr: true},
"Error_when_unmount_fails": {unmountErr: true, wantErr: true},
"Error_when_dir_path_is_empty": {emptyDirError: true, wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -173,8 +174,8 @@ func TestGetLuksKeyFromRecoveryKey(t *testing.T) {
"Success_getting_luks_key_with_hex_flag": {hexFlag: true},
"Success_getting_luks_key_with_escaped_flag": {escapedFlag: true},

"Fail_getting_luks_key": {recoveryKey: "invalid", wantErr: true},
"Fail_for_too_many_flags": {wantErr: true, hexFlag: true, escapedFlag: true},
"Error_getting_luks_key": {recoveryKey: "invalid", wantErr: true},
"Error_for_too_many_flags": {wantErr: true, hexFlag: true, escapedFlag: true},
}

for name, tc := range tests {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tpmctl/integrationtests/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestRemove(t *testing.T) {
}{
"Success_on_removing": {},

"Fail_on_user_privilege": {nonRootUser: true, wantErr: true},
"Fail_on_removing": {wantErr: true},
"Error_on_user_privilege": {nonRootUser: true, wantErr: true},
"Error_on_removing": {wantErr: true},
}
for _, command := range commands {
for name, tc := range tests {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tpmctl/integrationtests/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestReplace(t *testing.T) {
}{
"Success_on_replacing": {},

"Fail_on_validating": {wantErr: true},
"Fail_on_replacing": {wantErr: true},
"Error_on_validating": {wantErr: true},
"Error_on_replacing": {wantErr: true},
}

for _, command := range commands {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tpmctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestRun(t *testing.T) {
want int
wantInLog string
}{
"Returns 0 on success": {app: mockApp{err: nil}, want: 0},
"Returns 1 when got an error": {app: mockApp{err: errors.New("desired error")}, want: 1, wantInLog: "desired error"},
"Returns 0 on success": {app: mockApp{err: nil}, want: 0},
"Returns 1 on error": {app: mockApp{err: errors.New("desired error")}, want: 1, wantInLog: "desired error"},
}

for name, tc := range tests {
Expand Down
12 changes: 6 additions & 6 deletions internal/tpm/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAddPassphrase(t *testing.T) {
}{
"Success_adding_passphrase": {passphrase: "test"},

"Fail_adding_passphrase": {wantErr: true},
"Error_adding_passphrase": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestReplacePassphrase(t *testing.T) {
}{
"Success_replacing_passphrase": {old: "old", new: "new"},

"Fail_replacing_passphrase": {wantErr: true},
"Error_replacing_passphrase": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestRemovePassphrase(t *testing.T) {
}{
"Success_removing_passphrase": {},

"Fail_removing_passphrase": {wantErr: true},
"Error_removing_passphrase": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestAddPIN(t *testing.T) {
}{
"Success_adding_pin": {pin: "123456"},

"Fail_adding_pin": {wantErr: true},
"Error_adding_pin": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestReplacePIN(t *testing.T) {
}{
"Success_replacing_pin": {old: "123456", new: "654321"},

"Fail_replacing_pin": {wantErr: true},
"Error_replacing_pin": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestRemovePIN(t *testing.T) {
}{
"Success_removing_pin": {},

"Fail_removing_pin": {wantErr: true},
"Error_removing_pin": {wantErr: true},
}

for name, tc := range tests {
Expand Down
30 changes: 15 additions & 15 deletions internal/tpm/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func TestMountVolume(t *testing.T) {
wantMounted: true,
},

"Error out when unable to crate directory": {mkdirErr: true, wantErr: true},
"Error out when authRequestor fails": {authRequestor: authRequestor{wantErr: true}, wantErr: true},
"Error out when unable to mount volume": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantRequested: true, wantErr: true},
"Error out when volume is already mounted": {alreadyMountedErr: true, wantErr: true},
"Error out when unable to locate volume": {readErr: true, wantErr: true},
"Error out when systemd-cryptsetup fails": {device: "exit-with-failure", wantRequested: true, wantErr: true},
"Error out when device is already in use by another tool": {deviceInUse: true, wantErr: true},
"Error out when device is cannot be located": {deviceInUse: true, classBlockErr: true, wantErr: true},
"Error when unable to create directory": {mkdirErr: true, wantErr: true},
"Error when authRequestor fails": {authRequestor: authRequestor{wantErr: true}, wantErr: true},
"Error when unable to mount volume": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantRequested: true, wantErr: true},
"Error when volume is already mounted": {alreadyMountedErr: true, wantErr: true},
"Error when unable to locate volume": {readErr: true, wantErr: true},
"Error when systemd cryptsetup fails": {device: "exit-with-failure", wantRequested: true, wantErr: true},
"Error when device is already in use by another tool": {deviceInUse: true, wantErr: true},
"Error when device cannot be located": {deviceInUse: true, classBlockErr: true, wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -132,11 +132,11 @@ func TestUnmountVolume(t *testing.T) {
}{
"Success on unmounting volume": {wantUnmounted: true},

"Error out when unable to remove directory": {wantRmdirErr: true, wantErr: true},
"Error out when unable determine device path": {readErr: true, wantErr: true},
"Error out when path is not found": {target: "not-existing-target", wantErr: true},
"Error out when unable to unmount volume": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantErr: true},
"Error out when systemd-cryptsetup fails": {mapper: "exit-with-failure", wantErr: true},
"Error when unable to remove directory": {wantRmdirErr: true, wantErr: true},
"Error when unable to determine device path": {readErr: true, wantErr: true},
"Error when path is not found": {target: "not-existing-target", wantErr: true},
"Error when unable to unmount volume": {syscall: tpmtestutils.TestSyscall{WantErr: true}, wantErr: true},
"Error when systemd cryptsetup fails": {mapper: "exit-with-failure", wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -218,8 +218,8 @@ func TestSearchInProcMounts(t *testing.T) {
"Success on getting mapper": {fieldPath: 0, fieldResult: 1},
"Success with no path found in /proc/mounts": {path: "wrong-path", notFound: true},

"Fail to open /proc/mounts": {fileErr: true, wantErr: true},
"Fail to read /proc/mounts": {readErr: true, wantErr: true},
"Error opening /proc/mounts": {fileErr: true, wantErr: true},
"Error reading /proc/mounts": {readErr: true, wantErr: true},
}

for name, tc := range tests {
Expand Down
12 changes: 6 additions & 6 deletions internal/tpm/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func TestCreateKey(t *testing.T) {
}{
"Success_creating_recovery_key": {recoveryKeyName: "test", recoveryKey: "11272-47509-28031-54818-41671-38673-11053-06376"},

"Fail_generating_recovery_key": {wantErr: true},
"Fail_adding_recovery_key": {wantErr: true},
"Error_generating_recovery_key": {wantErr: true},
"Error_adding_recovery_key": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -59,8 +59,8 @@ func TestRegenerateKey(t *testing.T) {
}{
"Success_regenerating_recovery_key": {recoveryKeyName: "test", recoveryKey: "11272-47509-28031-54818-41671-38673-11053-06376"},

"Fail_generating_recovery_key": {wantErr: true},
"Fail_adding_recovery_key": {wantErr: true},
"Error_generating_recovery_key": {wantErr: true},
"Error_adding_recovery_key": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestCheckKey(t *testing.T) {
}{
"Success_checking_recovery_key": {recoveryKey: "11272-47509-28031-54818-41671-38673-11053-06376"},

"Fail_checking_recovery_key": {wantErr: true},
"Error_checking_recovery_key": {wantErr: true},
}

for name, tc := range tests {
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestGetLuksKey(t *testing.T) {
}{
"Success_getting_luks_key": {recoveryKey: "11272-47509-28031-54818-41671-38673-11053-06376"},

"Fail_getting_luks_key": {wantErr: true},
"Error_getting_luks_key": {wantErr: true},
}

for name, tc := range tests {
Expand Down