2025-11-02 21:23:13 +00:00
|
|
|
package crypt
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
2025-11-13 21:27:38 +00:00
|
|
|
// TestEnsureRSA_Good tests that the RSA service is initialized correctly.
|
|
|
|
|
func TestEnsureRSA_Good(t *testing.T) {
|
2025-11-02 21:23:13 +00:00
|
|
|
s := &Service{}
|
|
|
|
|
s.ensureRSA()
|
2025-11-03 00:17:27 +00:00
|
|
|
assert.NotNil(t, s.rsa)
|
2025-11-02 21:23:13 +00:00
|
|
|
}
|
2025-11-13 21:27:38 +00:00
|
|
|
|
|
|
|
|
// TestEnsureRSA_Bad tests that calling ensureRSA multiple times does not change the RSA service.
|
|
|
|
|
func TestEnsureRSA_Bad(t *testing.T) {
|
|
|
|
|
s := &Service{}
|
|
|
|
|
s.ensureRSA()
|
|
|
|
|
rsa1 := s.rsa
|
|
|
|
|
s.ensureRSA()
|
|
|
|
|
rsa2 := s.rsa
|
|
|
|
|
assert.Same(t, rsa1, rsa2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestEnsureRSA_Ugly tests that ensureRSA works correctly on a service with a pre-initialized RSA service.
|
|
|
|
|
func TestEnsureRSA_Ugly(t *testing.T) {
|
|
|
|
|
s := NewService() // NewService initializes the RSA service
|
|
|
|
|
rsa1 := s.rsa
|
|
|
|
|
s.ensureRSA()
|
|
|
|
|
rsa2 := s.rsa
|
|
|
|
|
assert.Same(t, rsa1, rsa2)
|
|
|
|
|
}
|