| 1 |
package state_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/state" |
| 7 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/test/testsuite" |
| 8 |
"github.com/stretchr/testify/require" |
| 9 |
) |
| 10 |
|
| 11 |
func benchmarkSessionState() state.State { |
| 12 |
return state.State{ |
| 13 |
Client: state.ClientIdentifier{ |
| 14 |
CID: 9223372036854775807, |
| 15 |
KID: 2, |
| 16 |
CommonName: "test", |
| 17 |
}, |
| 18 |
IPAddr: "127.0.0.1", |
| 19 |
IPPort: "12345", |
| 20 |
SessionState: "", |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
func BenchmarkStateEncrypt(b *testing.B) { |
| 25 |
cipher := testsuite.NewCipher(b) |
| 26 |
sessionState := benchmarkSessionState() |
| 27 |
|
| 28 |
var encryptedState state.EncryptedState |
| 29 |
|
| 30 |
b.ReportAllocs() |
| 31 |
b.ResetTimer() |
| 32 |
|
| 33 |
for b.Loop() { |
| 34 |
var err error |
| 35 |
|
| 36 |
encryptedState, err = state.Encrypt(cipher, sessionState) |
| 37 |
if err != nil { |
| 38 |
b.Fatal(err) |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
_ = encryptedState |
| 43 |
} |
| 44 |
|
| 45 |
func BenchmarkStateDecrypt(b *testing.B) { |
| 46 |
cipher := testsuite.NewCipher(b) |
| 47 |
encodedTokenString, err := state.Encrypt(cipher, benchmarkSessionState()) |
| 48 |
require.NoError(b, err) |
| 49 |
|
| 50 |
var decryptedState state.State |
| 51 |
|
| 52 |
b.ReportAllocs() |
| 53 |
b.ResetTimer() |
| 54 |
|
| 55 |
for b.Loop() { |
| 56 |
var decryptErr error |
| 57 |
|
| 58 |
decryptedState, decryptErr = state.Decrypt(cipher, encodedTokenString) |
| 59 |
if decryptErr != nil { |
| 60 |
b.Fatal(decryptErr) |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
_ = decryptedState |
| 65 |
} |