crypt_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX files. Support reads and writes XLSX file generated by
  7. // Microsoft Excel™ 2007 and later. Support save file without losing original
  8. // charts of XLSX. This library needs Go version 1.15 or later.
  9. package excelize
  10. import (
  11. "path/filepath"
  12. "testing"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestEncrypt(t *testing.T) {
  16. f, err := OpenFile(filepath.Join("test", "encryptSHA1.xlsx"), Options{Password: "password"})
  17. assert.NoError(t, err)
  18. assert.EqualError(t, f.SaveAs(filepath.Join("test", "BadEncrypt.xlsx"), Options{Password: "password"}), "not support encryption currently")
  19. }
  20. func TestEncryptionMechanism(t *testing.T) {
  21. mechanism, err := encryptionMechanism([]byte{3, 0, 3, 0})
  22. assert.Equal(t, mechanism, "extensible")
  23. assert.EqualError(t, err, "unsupport encryption mechanism")
  24. _, err = encryptionMechanism([]byte{})
  25. assert.EqualError(t, err, "unknown encryption mechanism")
  26. }
  27. func TestHashing(t *testing.T) {
  28. assert.Equal(t, hashing("unsupportHashAlgorithm", []byte{}), []uint8([]byte(nil)))
  29. }