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
|
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
//go:build windows
// +build windows
package accessor
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestWriteEncryption(t *testing.T) {
p := filepath.Join(t.TempDir(), t.Name())
a, err := New(p)
require.NoError(t, err)
data := []byte(`{"key":"value"}`)
require.NoError(t, json.Unmarshal(data, &struct{}{}), "test bug: data should unmarshal")
require.NoError(t, a.Write(ctx, data))
// Write should have encrypted data before writing it to the file
actual, err := os.ReadFile(p)
require.NoError(t, err)
require.NotEmpty(t, actual)
err = json.Unmarshal(actual, &struct{}{})
require.Error(t, err, "Unmarshal should fail because the file's content, being encrypted, isn't JSON")
}
|