Skip to content

Commit

Permalink
Server name override (#9)
Browse files Browse the repository at this point in the history
* added cname override

* updated tests
  • Loading branch information
jamisonhyatt authored and bojand committed Apr 14, 2018
1 parent c588445 commit 055fab8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/grpcannon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
proto = flag.String("proto", "", `The .proto file.`)
call = flag.String("call", "", `A fully-qualified symbol name.`)
cert = flag.String("cert", "", "Client certificate file. If Omitted insecure is used.")
cname = flag.String("cname", "", "Server Cert CName Override - useful for self signed certs")

c = flag.Int("c", 50, "Number of requests to run concurrently.")
n = flag.Int("n", 200, "Number of requests to run. Default is 200.")
Expand Down Expand Up @@ -54,6 +55,7 @@ Options:
-proto The protocol buffer file.
-call A fully-qualified method name in 'service/method' or 'service.method' format.
-cert The file containing the CA root cert file.
-cname an override of the expect Server Cname presented by the server.
-c Number of requests to run concurrently. Total number of requests cannot
be smaller than the concurrency level. Default is 50.
Expand Down Expand Up @@ -117,7 +119,7 @@ func main() {
iPaths = strings.Split(pathsTrimmed, ",")
}

cfg, err = config.New(*proto, *call, *cert, *n, *c, *q, *z, *t,
cfg, err = config.New(*proto, *call, *cert, *cname, *n, *c, *q, *z, *t,
*data, *dataPath, *md, *mdPath, *output, *format, host, *ct, *kt, *cpus, iPaths)
if err != nil {
errAndExit(err.Error())
Expand Down Expand Up @@ -163,6 +165,7 @@ func runTest(config *config.Config) (*grpcannon.Report, error) {
opts := &grpcannon.Options{
Host: config.Host,
Cert: config.Cert,
CName: config.CName,
N: config.N,
C: config.C,
QPS: config.QPS,
Expand Down
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
Proto string `json:"proto"`
Call string `json:"call"`
Cert string `json:"cert"`
CName string `json:"cName"`
N int `json:"n"`
C int `json:"c"`
QPS int `json:"q"`
Expand All @@ -36,14 +37,15 @@ type Config struct {
}

// NewConfig creates a new config
func New(proto, call, cert string, n, c, qps int, z time.Duration, timeout int,
func New(proto, call, cert, cName string, n, c, qps int, z time.Duration, timeout int,
data, dataPath, metadata, mdPath, output, format, host string,
dialTimout, keepaliveTime, cpus int, importPaths []string) (*Config, error) {

cfg := &Config{
Proto: proto,
Call: call,
Cert: cert,
CName: cName,
N: n,
C: c,
QPS: qps,
Expand Down
4 changes: 3 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)

const expected = `{"proto":"asdf","call":"","cert":"","n":0,"c":0,"q":0,"t":0,"D":"","M":"","o":"","O":"oval","host":"","T":0,"L":0,"cpus":0,"z":"4h30m0s"}`
const expected = `{"proto":"asdf","call":"","cert":"","cName":"","n":0,"c":0,"q":0,"t":0,"D":"","M":"","o":"","O":"oval","host":"","T":0,"L":0,"cpus":0,"z":"4h30m0s"}`

func TestConfig_MarshalJSON(t *testing.T) {
z, _ := time.ParseDuration("4h30m")
Expand Down Expand Up @@ -260,6 +260,7 @@ func TestConfig_ReadConfig(t *testing.T) {
Call: "mycall",
Data: data,
Cert: "mycert",
CName: "localhost",
N: 200,
C: 50,
QPS: 0,
Expand Down Expand Up @@ -298,6 +299,7 @@ func TestConfig_ReadConfig(t *testing.T) {
Call: "mycall",
Data: data,
Cert: "mycert",
CName: "localhost",
N: 200,
C: 50,
QPS: 0,
Expand Down
3 changes: 2 additions & 1 deletion requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
type Options struct {
Host string
Cert string
CName string
N int
C int
QPS int
Expand Down Expand Up @@ -300,7 +301,7 @@ func (b *Requester) makeBidiRequest(ctx *context.Context) {
func createClientCredOption(config *Options) (grpc.DialOption, error) {
credOptions := grpc.WithInsecure()
if strings.TrimSpace(config.Cert) != "" {
creds, err := credentials.NewClientTLSFromFile(config.Cert, "")
creds, err := credentials.NewClientTLSFromFile(config.Cert, config.CName)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions testdata/cfgpath.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"proto": "my.proto",
"call": "mycall",
"cert": "mycert",
"cName": "localhost",
"D": "./data.json",
"M": "./metadata.json",
"i": [
Expand Down
1 change: 1 addition & 0 deletions testdata/grpcannon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"proto": "my.proto",
"call": "mycall",
"cert": "mycert",
"cName": "localhost",
"d": {
"name": "mydata"
},
Expand Down

0 comments on commit 055fab8

Please sign in to comment.