You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

secret_test.go 745B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package secret
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestNew(t *testing.T) {
  10. result, err := New()
  11. assert.NoError(t, err)
  12. assert.True(t, len(result) == 44)
  13. result2, err := New()
  14. assert.NoError(t, err)
  15. // check if secrets
  16. assert.NotEqual(t, result, result2)
  17. }
  18. func TestEncryptDecrypt(t *testing.T) {
  19. var hex string
  20. var str string
  21. hex, _ = EncryptSecret("foo", "baz")
  22. str, _ = DecryptSecret("foo", hex)
  23. assert.Equal(t, str, "baz")
  24. hex, _ = EncryptSecret("bar", "baz")
  25. str, _ = DecryptSecret("foo", hex)
  26. assert.NotEqual(t, str, "baz")
  27. }