-
Notifications
You must be signed in to change notification settings - Fork 4
fix(keychain): store large blobs on windows #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,73 @@ import ( | |
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestChunkBlob(t *testing.T) { | ||
| t.Run("empty blob returns no chunks", func(t *testing.T) { | ||
| assert.Empty(t, chunkBlob(nil, 4)) | ||
| assert.Empty(t, chunkBlob([]byte{}, 4)) | ||
| }) | ||
| t.Run("blob smaller than size is a single chunk", func(t *testing.T) { | ||
| blob := []byte{1, 2, 3} | ||
| chunks := chunkBlob(blob, 4) | ||
| assert.Len(t, chunks, 1) | ||
| assert.Equal(t, blob, chunks[0]) | ||
| }) | ||
| t.Run("blob exactly size is a single chunk", func(t *testing.T) { | ||
| blob := []byte{1, 2, 3, 4} | ||
| chunks := chunkBlob(blob, 4) | ||
| assert.Len(t, chunks, 1) | ||
| assert.Equal(t, blob, chunks[0]) | ||
| }) | ||
| t.Run("blob splits into equal chunks", func(t *testing.T) { | ||
| blob := []byte{1, 2, 3, 4, 5, 6, 7, 8} | ||
| chunks := chunkBlob(blob, 4) | ||
| assert.Len(t, chunks, 2) | ||
| assert.Equal(t, []byte{1, 2, 3, 4}, chunks[0]) | ||
| assert.Equal(t, []byte{5, 6, 7, 8}, chunks[1]) | ||
| }) | ||
| t.Run("blob splits with remainder in last chunk", func(t *testing.T) { | ||
| blob := []byte{1, 2, 3, 4, 5} | ||
| chunks := chunkBlob(blob, 4) | ||
| assert.Len(t, chunks, 2) | ||
| assert.Equal(t, []byte{1, 2, 3, 4}, chunks[0]) | ||
| assert.Equal(t, []byte{5}, chunks[1]) | ||
| }) | ||
| t.Run("reassembled chunks equal original blob", func(t *testing.T) { | ||
| blob := make([]byte, 2560*3+100) | ||
| for i := range blob { | ||
| blob[i] = byte(i % 256) | ||
| } | ||
| chunks := chunkBlob(blob, maxBlobSize) | ||
| assert.Len(t, chunks, 4) | ||
|
|
||
| var reassembled []byte | ||
| for _, c := range chunks { | ||
| reassembled = append(reassembled, c...) | ||
| } | ||
| assert.Equal(t, blob, reassembled) | ||
| }) | ||
| } | ||
|
|
||
| func TestIsChunkCredential(t *testing.T) { | ||
| t.Run("returns true when chunk:index attribute is present", func(t *testing.T) { | ||
| attrs := []wincred.CredentialAttribute{ | ||
| {Keyword: chunkIndexKey, Value: []byte("0")}, | ||
| } | ||
| assert.True(t, isChunkCredential(attrs)) | ||
| }) | ||
| t.Run("returns false when chunk:index attribute is absent", func(t *testing.T) { | ||
| attrs := []wincred.CredentialAttribute{ | ||
| {Keyword: serviceGroupKey, Value: []byte("group")}, | ||
| {Keyword: serviceNameKey, Value: []byte("name")}, | ||
| } | ||
| assert.False(t, isChunkCredential(attrs)) | ||
| }) | ||
| t.Run("returns false for empty attributes", func(t *testing.T) { | ||
| assert.False(t, isChunkCredential(nil)) | ||
| assert.False(t, isChunkCredential([]wincred.CredentialAttribute{})) | ||
| }) | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want some more tests that verify Save/Filter/Get/Delete on credentials that need to be chunked work as expected?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. definitely, but i think this is good enough to get this fix in quickly |
||
| func TestMapWindowsAttributes(t *testing.T) { | ||
| t.Run("can map to windows attributes", func(t *testing.T) { | ||
| attributes := map[string]string{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to dedupe this? Seeing the same code above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verbosity is best here