| 1 |
package internal_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
"strings" |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config" |
| 9 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/test/testsuite" |
| 10 |
"github.com/stretchr/testify/require" |
| 11 |
) |
| 12 |
|
| 13 |
func BenchmarkFull(b *testing.B) { |
| 14 |
b.StopTimer() |
| 15 |
|
| 16 |
conf := config.Config{} |
| 17 |
suite := testsuite.New(&conf, testsuite.WithDiscardLogger()) |
| 18 |
suite.SetupMockEnvironment(b.Context(), b, nil) |
| 19 |
suite.ExpectVersionAndReleaseHold(b) |
| 20 |
|
| 21 |
clientConnectMessage := strings.Join([]string{ |
| 22 |
">CLIENT:CONNECT,0,1", |
| 23 |
">CLIENT:ENV,n_clients=0", |
| 24 |
">CLIENT:ENV,password=", |
| 25 |
">CLIENT:ENV,untrusted_port=17016", |
| 26 |
">CLIENT:ENV,untrusted_ip=192.168.65.1", |
| 27 |
">CLIENT:ENV,[email protected]", |
| 28 |
">CLIENT:ENV,username=", |
| 29 |
">CLIENT:ENV,IV_BS64DL=1", |
| 30 |
">CLIENT:ENV,IV_SSO=webauth,openurl,crtext", |
| 31 |
">CLIENT:ENV,IV_GUI_VER=OCmacOS_3.4.4-4629", |
| 32 |
">CLIENT:ENV,IV_AUTO_SESS=1", |
| 33 |
">CLIENT:ENV,IV_CIPHERS=AES-128-GCM:AES-192-GCM:CHACHA20-POLY1305", |
| 34 |
">CLIENT:ENV,IV_MTU=1600", |
| 35 |
">CLIENT:ENV,IV_PROTO=990", |
| 36 |
">CLIENT:ENV,IV_TCPNL=1", |
| 37 |
">CLIENT:ENV,IV_NCP=2", |
| 38 |
">CLIENT:ENV,IV_PLAT=mac", |
| 39 |
">CLIENT:ENV,IV_VER=3.8.1", |
| 40 |
">CLIENT:ENV,tls_serial_hex_0=51:b3:55:90:65:af:71:5c:d5:52:2b:0b:00:14:8d:ee", |
| 41 |
">CLIENT:ENV,tls_serial_0=108598624241397715647038806614705737198", |
| 42 |
">CLIENT:ENV,tls_digest_sha256_0=d3:6d:1d:96:f8:bd:7e:e8:db:c4:0f:53:a1:76:f0:ca:9e:78:63:bf:c6:4a:ac:b9:e6:ed:84:62:f5:ac:5d:b8", |
| 43 |
">CLIENT:ENV,tls_digest_0=b7:73:bd:6c:31:31:49:63:0d:0c:11:6d:0c:13:d0:b4:8f:97:33:7d", |
| 44 |
">CLIENT:ENV,[email protected]", |
| 45 |
">CLIENT:ENV,[email protected]", |
| 46 |
">CLIENT:ENV,tls_serial_hex_1=01:b3:95:f8:1a:9f:9f:fe:7c:27:ad:29:c1:93:23:ae:08:7f:ab:36", |
| 47 |
">CLIENT:ENV,tls_serial_1=9713888317380397892476539918183380788698917686", |
| 48 |
">CLIENT:ENV,tls_digest_sha256_1=75:1a:a1:63:bb:e9:c7:f3:e3:bf:e1:08:f1:36:b7:36:90:04:da:dd:b8:78:b1:cf:d5:ac:09:b6:36:31:a7:db", |
| 49 |
">CLIENT:ENV,tls_digest_1=d4:bc:00:89:e5:01:0c:27:3d:ea:4a:b5:42:8b:f7:3d:19:7a:a2:25", |
| 50 |
">CLIENT:ENV,tls_id_1=CN=Easy-RSA CA", |
| 51 |
">CLIENT:ENV,X509_1_CN=Easy-RSA CA", |
| 52 |
">CLIENT:ENV,remote_port_1=1194", |
| 53 |
">CLIENT:ENV,local_port_1=1194", |
| 54 |
">CLIENT:ENV,proto_1=udp", |
| 55 |
">CLIENT:ENV,daemon_pid=7", |
| 56 |
">CLIENT:ENV,daemon_start_time=1703401559", |
| 57 |
">CLIENT:ENV,daemon_log_redirect=0", |
| 58 |
">CLIENT:ENV,daemon=0", |
| 59 |
">CLIENT:ENV,verb=3", |
| 60 |
">CLIENT:ENV,config=/etc/openvpn/openvpn.conf", |
| 61 |
">CLIENT:ENV,ifconfig_local=100.64.0.1", |
| 62 |
">CLIENT:ENV,ifconfig_netmask=255.255.255.0", |
| 63 |
">CLIENT:ENV,script_context=init", |
| 64 |
">CLIENT:ENV,tun_mtu=1500", |
| 65 |
">CLIENT:ENV,dev=tun0", |
| 66 |
">CLIENT:ENV,dev_type=tun", |
| 67 |
">CLIENT:ENV,redirect_gateway=0", |
| 68 |
">CLIENT:ENV,END", |
| 69 |
}, "\r\n") + "\r\n" |
| 70 |
|
| 71 |
var authURL string |
| 72 |
|
| 73 |
b.ResetTimer() |
| 74 |
b.StartTimer() |
| 75 |
|
| 76 |
for b.Loop() { |
| 77 |
suite.SendMessagef(b, clientConnectMessage) |
| 78 |
|
| 79 |
authURL = testsuite.GetAuthURLFromMessage(suite.ReadLine(b)) |
| 80 |
suite.SendMessagef(b, "SUCCESS: client-pending-auth command succeeded") |
| 81 |
|
| 82 |
_, _, err := suite.DoHTTPRequest(b, http.MethodGet, authURL, nil, http.NoBody) //nolint:bodyclose |
| 83 |
require.NoError(b, err) |
| 84 |
|
| 85 |
suite.ExpectMessage(b, "client-auth-nt 0 1") |
| 86 |
suite.SendMessagef(b, "SUCCESS: client-auth command succeeded") |
| 87 |
} |
| 88 |
|
| 89 |
b.StopTimer() |
| 90 |
|
| 91 |
suite.Close(b) |
| 92 |
|
| 93 |
b.ReportAllocs() |
| 94 |
} |