-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathcredman_windows_test.go
More file actions
85 lines (67 loc) · 2.87 KB
/
credman_windows_test.go
File metadata and controls
85 lines (67 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package credman
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestWriteCredential(t *testing.T) {
credential := &Credential{
TargetName: "TestTargetName",
Comment: "TestComment",
LastWritten: time.Now(),
UserName: "TestUsername",
Persist: PersistSession,
CredentialBlob: []byte{0x65, 0x66},
}
err := WriteCredential(credential, CredTypeGeneric)
assert.NoErrorf(t, err, "WriteCredential returned an error: %v", err)
// Check if the written credential can be retrieved
credentials, _ := EnumerateCredentials("TestTargetName", false)
assert.NotEqual(t, len(credentials), 0, "WriteCredential failed to write the credential")
assert.Equal(t, credentials[0].TargetName, "TestTargetName", "WriteCredential wrote incorrect TargetName, got: %s, want: %s", credentials[0].TargetName, "TestTargetName")
assert.Equal(t, credentials[0].Comment, "TestComment", "WriteCredential wrote incorrect Comment, got: %s, want: %s", credentials[0].Comment, "TestComment")
assert.Equal(t, credentials[0].UserName, "TestUsername", "WriteCredential wrote incorrect UserName, got: %s, want: %s", credentials[0].UserName, "TestUsername")
assert.Equal(t, credentials[0].Persist, PersistSession, "WriteCredential wrote incorrect Persist, got: %d, want: %d", credentials[0].Persist, PersistSession)
// Cleanup the written credential
_ = DeleteCredential(credential, CredTypeGeneric)
}
func TestDeleteCredential(t *testing.T) {
credential := &Credential{
TargetName: "TestTargetName",
Comment: "TestComment",
LastWritten: time.Now(),
UserName: "TestUsername",
Persist: PersistSession,
}
// Write the credential first
_ = WriteCredential(credential, CredTypeGeneric)
err := DeleteCredential(credential, CredTypeGeneric)
assert.NoErrorf(t, err, "DeleteCredential returned an error: %v", err)
// Check if the deleted credential still exists
credentials, _ := EnumerateCredentials("TestTargetName", false)
assert.Equal(t, len(credentials), 0, "DeleteCredential failed to delete the credential")
}
func TestNegDeleteCredential(t *testing.T) {
credential := &Credential{}
err := DeleteCredential(credential, CredTypeGeneric)
assert.Errorf(t, err, "err should not be nil")
}
func TestNegWriteCredential(t *testing.T) {
credential := &Credential{}
err := WriteCredential(credential, CredTypeGeneric)
assert.Errorf(t, err, "err should not be nil")
}
func TestNegConvertFromSystemCredential(t *testing.T) {
result := convertFromSystemCredential(nil)
assert.Nil(t, result, "result should be nil")
}
func TestNegConvertToSystemCredential(t *testing.T) {
result := convertToSystemCredential(nil)
assert.Nil(t, result, "result should be nil")
}
func TestNegcopyBytesToSlice(t *testing.T) {
b := copyBytesToSlice(nil, 0)
assert.Len(t, b, 0, "bytes should be empty")
}