Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show more test info #15

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
package cmd

import (
"context"
"crypto/tls"
"fmt"
"log"
"math"
"net"
"net/http"
Expand Down Expand Up @@ -166,3 +168,19 @@ func Max(a, b int) int {
}
return b
}

// GetSobject retrieves a sobject through SDKMS client.
// It takes a keyID as a parameter and returns a pointer to a Sobject.
// If the keyID is empty, it will return an error.
// If an error occurs during the retrieval process, the function will log a fatal error and exit.
func GetSobject(kid *string) *sdkms.Sobject {
client := sdkmsClient()
client.Auth = sdkms.APIKey(apiKey)
Taowyoo marked this conversation as resolved.
Show resolved Hide resolved
key, err := client.GetSobject(context.Background(), nil, sdkms.SobjectDescriptor{
Kid: kid,
})
if err != nil {
log.Fatalf("Fatal error: %v\n", err)
}
return key
}
9 changes: 9 additions & 0 deletions cmd/loadTestAsymmetricCrypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package cmd

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -35,6 +36,9 @@ func init() {
}

func asymmetricCryptoLoadTest() {
// get basic info of the given sobject
key := GetSobject(&keyID)

setup := func(client *sdkms.Client) (interface{}, error) {
if createSession {
_, err := client.AuthenticateWithAPIKey(context.Background(), apiKey)
Expand All @@ -56,13 +60,18 @@ func asymmetricCryptoLoadTest() {
}
return asymmetricEncrypt(client)
}

// construct test name
name := "asymmetric encryption"
if decryptOpt {
name = "asymmetric decryption"
}
if createSession {
name += " with session"
}
name = fmt.Sprintf("%s %d %s", key.ObjType, *key.KeySize, name)

// start the load test
loadTest(name, setup, test, cleanup)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/loadTestGenerateKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func loadTestGenerateKey() {
d, p, err := generateKey(client)
return nil, d, p, err
}
name := fmt.Sprintf("generate %v keys", keyType)
name := fmt.Sprintf("generate %v key", keyType)
if keyType == objectTypeAES || keyType == objectTypeRSA {
name += fmt.Sprintf(" (%v bits)", keySize)
}
Expand Down
21 changes: 16 additions & 5 deletions cmd/loadTestInvokePlugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"time"

"github.com/fortanix/sdkms-client-go/sdkms"
Expand Down Expand Up @@ -39,11 +39,18 @@ func init() {
}

func invokePluginLoadTest() {
// Get the given plugin from the server
client := sdkmsClient()
client.Auth = sdkms.APIKey(apiKey)
plugin, err := client.GetPlugin(context.Background(), pluginID)
if err != nil {
log.Fatalf("Fatal error: %v\n", err)
}

input := json.RawMessage(pluginInput)
_, err := json.Marshal(&input)
_, err = json.Marshal(&input)
if err != nil {
fmt.Printf("plugin input must be valid JSON: %v\n", err)
os.Exit(1)
log.Fatalf("Plugin input must be valid JSON: %v\n", err)
}

setup := func(client *sdkms.Client) (interface{}, error) {
Expand All @@ -62,10 +69,14 @@ func invokePluginLoadTest() {
test := func(client *sdkms.Client, stage loadTestStage, arg interface{}) (interface{}, time.Duration, profilingDataStr, error) {
return invokePlugin(client)
}
name := "plugin invocation"

// construct test name
name := fmt.Sprintf("invoke plugin '%s'", plugin.Name)
if createSession {
name += " with session"
}

// start the load test
loadTest(name, setup, test, cleanup)
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/loadTestSignVerify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package cmd

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -38,6 +39,9 @@ func init() {
}

func signVerifyLoadTest() {
// get basic info of the given sobject
key := GetSobject(&signKeyID)

setup := func(client *sdkms.Client) (interface{}, error) {
if createSession {
_, err := client.AuthenticateWithAPIKey(context.Background(), apiKey)
Expand All @@ -59,13 +63,17 @@ func signVerifyLoadTest() {
}
return sign(client)
}

// construct test name
name := "sign"
if verifyOpt {
name = "verify"
}
if createSession {
name += " with session"
}
name = fmt.Sprintf("%s %d %s", key.ObjType, *key.KeySize, name)

loadTest(name, setup, test, cleanup)
}

Expand Down
11 changes: 10 additions & 1 deletion cmd/loadTestSymmetricCrypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package cmd

import (
"context"
"fmt"
"log"
"net/http"
"time"
Expand Down Expand Up @@ -40,10 +41,13 @@ func init() {
symmetricCryptoLoadTestCmd.PersistentFlags().StringVar(&keyID, "kid", "", "Key ID to use for symmetric crypto")
symmetricCryptoLoadTestCmd.PersistentFlags().BoolVar(&decryptOpt, "decrypt", false, "Perform decryption instead of encryption")
symmetricCryptoLoadTestCmd.PersistentFlags().StringVar(&cipherModeStr, "mode", "CBC", "Cipher mode used for encryption/decryption, support: CBC, GCM, FPE")
cipherMode = validateCipherMode(cipherModeStr)
}

func symmetricCryptoLoadTest() {
cipherMode = validateCipherMode(cipherModeStr)
// get basic info of the given sobject
key := GetSobject(&keyID)

setup := func(client *sdkms.Client) (interface{}, error) {
if createSession {
_, err := client.AuthenticateWithAPIKey(context.Background(), apiKey)
Expand All @@ -65,6 +69,8 @@ func symmetricCryptoLoadTest() {
}
return encrypt(client)
}

// construct test name
name := "symmetric encryption"
if decryptOpt {
name = "symmetric decryption"
Expand All @@ -73,6 +79,9 @@ func symmetricCryptoLoadTest() {
if createSession {
name += " with session"
}
name = fmt.Sprintf("%s %d %s", key.ObjType, *key.KeySize, name)

// start the load test
loadTest(name, setup, test, cleanup)
}

Expand Down