| 1 |
package openvpn //nolint:testpackage |
| 2 |
|
| 3 |
import ( |
| 4 |
"strings" |
| 5 |
"testing" |
| 6 |
"time" |
| 7 |
|
| 8 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/openvpn/connection" |
| 9 |
) |
| 10 |
|
| 11 |
func BenchmarkBuildOAuth2StartURL(b *testing.B) { |
| 12 |
encryptedOIDCState := strings.Repeat("a", 256) |
| 13 |
|
| 14 |
var startURL string |
| 15 |
|
| 16 |
b.ReportAllocs() |
| 17 |
|
| 18 |
for b.Loop() { |
| 19 |
startURL = buildOAuth2StartURL("https://vpn.example.com/", encryptedOIDCState) |
| 20 |
} |
| 21 |
|
| 22 |
_ = startURL |
| 23 |
} |
| 24 |
|
| 25 |
func BenchmarkBuildClientPendingAuthCommand(b *testing.B) { |
| 26 |
client := connection.Client{CID: 12345, KID: 67890} |
| 27 |
startURL := "https://vpn.example.com/oauth2/start?state=" + strings.Repeat("a", 256) |
| 28 |
|
| 29 |
var ( |
| 30 |
command string |
| 31 |
err error |
| 32 |
) |
| 33 |
|
| 34 |
b.ReportAllocs() |
| 35 |
|
| 36 |
for b.Loop() { |
| 37 |
command, err = buildClientPendingAuthCommand(client, startURL, 300*time.Second) |
| 38 |
} |
| 39 |
|
| 40 |
if err != nil { |
| 41 |
b.Fatal(err) |
| 42 |
} |
| 43 |
|
| 44 |
_ = command |
| 45 |
} |