Skip to content

Commit 23424dc

Browse files
committed
Add TLS client config in request action
1 parent d2253df commit 23424dc

File tree

11 files changed

+755
-70
lines changed

11 files changed

+755
-70
lines changed

.mockery.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ packages:
1111
HttpClient: {}
1212
VegetaAttacker: {}
1313
VegetaMetrics: {}
14+
X509CertPool: {}
1415
github.com/wstool/wst/conf:
1516
config:
1617
dir: mocks/generated/conf

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ in the future.
4949

5050
#### Structure - Instances, Actions, Servers, Services
5151

52-
- add https verification options for request and bench
53-
- it should allow extending cert store with a selected cert
54-
- it should also allow disabling the verification
5552
- http/2 requests
5653
- add http_version field to the request action
5754
- update the client to allow using http/2
@@ -77,6 +74,9 @@ in the future.
7774
- support metrics server expectation
7875
- custom server actions for parallel and not action
7976
- this is mainly for completeness with sequential and might be also useful in some cases
77+
- support TLS config in bench action
78+
- this will likely require using custom transport
79+
- extend TLS config for request and bench to support client cert
8080
- integrate better instance action identification
8181
- it should introduce name for each action and also pass parent name to nested actions in `parallel` or `not`
8282
- add execute action custom environment variables support

app/foundation.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ package app
1616

1717
import (
1818
"context"
19+
"net/http"
20+
"os"
21+
"os/user"
22+
1923
"github.com/google/uuid"
2024
"github.com/spf13/afero"
2125
"go.uber.org/zap"
22-
"os"
23-
"os/user"
2426
)
2527

2628
type Foundation interface {
@@ -35,7 +37,8 @@ type Foundation interface {
3537
UserHomeDir() (string, error)
3638
LookupEnvVar(key string) (string, bool)
3739
ExecCommand(ctx context.Context, name string, args []string) Command
38-
HttpClient() HttpClient
40+
HttpClient(tr *http.Transport) HttpClient
41+
X509CertPool() X509CertPool
3942
VegetaAttacker() VegetaAttacker
4043
VegetaMetrics() VegetaMetrics
4144
GenerateUuid() string
@@ -112,11 +115,15 @@ func (f *DefaultFoundation) ExecCommand(ctx context.Context, name string, args [
112115
return NewExecCommand(ctx, name, args)
113116
}
114117

115-
func (f *DefaultFoundation) HttpClient() HttpClient {
118+
func (f *DefaultFoundation) HttpClient(tr *http.Transport) HttpClient {
116119
if f.dryRun {
117120
return NewDryRunHttpClient()
118121
}
119-
return NewRealHttpClient()
122+
return NewRealHttpClient(tr)
123+
}
124+
125+
func (f *DefaultFoundation) X509CertPool() X509CertPool {
126+
return NewX509CertPool()
120127
}
121128

122129
func (f *DefaultFoundation) VegetaMetrics() VegetaMetrics {

app/http.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ func (c *RealHttpClient) Do(req *http.Request) (*http.Response, error) {
4747
return c.client.Do(req)
4848
}
4949

50-
func NewRealHttpClient() HttpClient {
50+
func NewRealHttpClient(tr *http.Transport) HttpClient {
5151
return &RealHttpClient{
52-
client: &http.Client{},
52+
client: &http.Client{
53+
Transport: tr,
54+
},
5355
}
5456
}

app/x509.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package app
2+
3+
import "crypto/x509"
4+
5+
type X509CertPool interface {
6+
AppendCertFromPEM(pem string) bool
7+
CertPool() *x509.CertPool
8+
}
9+
10+
type x509CertPoolImpl struct {
11+
x509CertPool *x509.CertPool
12+
}
13+
14+
func (x x509CertPoolImpl) CertPool() *x509.CertPool {
15+
return x.x509CertPool
16+
}
17+
18+
func (x x509CertPoolImpl) AppendCertFromPEM(pem string) bool {
19+
return x.x509CertPool.AppendCertsFromPEM([]byte(pem))
20+
}
21+
22+
func NewX509CertPool() X509CertPool {
23+
return &x509CertPoolImpl{
24+
x509CertPool: x509.NewCertPool(),
25+
}
26+
}

conf/types/action.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,23 @@ type ExecuteAction struct {
108108
Env map[string]string `wst:"env"`
109109
}
110110

111+
type TLSClientConfig struct {
112+
SkipVerify bool `wst:"skip_verify,default=false"`
113+
CACert string `wst:"ca_certificate"`
114+
}
115+
111116
type RequestAction struct {
112-
Service string `wst:"service"`
113-
Timeout int `wst:"timeout"`
114-
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
115-
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
116-
Id string `wst:"id,default=last"`
117-
Scheme string `wst:"scheme,enum=http|https,default=http"`
118-
Path string `wst:"path"`
119-
EncodePath bool `wst:"encode_path,default=true"`
120-
Method string `wst:"method,enum=GET|HEAD|DELETE|POST|PUT|PATCH|PURGE,default=GET"`
121-
Headers Headers `wst:"headers"`
117+
Service string `wst:"service"`
118+
Timeout int `wst:"timeout"`
119+
When string `wst:"when,enum=always|on_success|on_failure,default=on_success"`
120+
OnFailure string `wst:"on_failure,enum=fail|ignore|skip,default=fail"`
121+
Id string `wst:"id,default=last"`
122+
Scheme string `wst:"scheme,enum=http|https,default=http"`
123+
Path string `wst:"path"`
124+
EncodePath bool `wst:"encode_path,default=true"`
125+
Method string `wst:"method,enum=GET|HEAD|DELETE|POST|PUT|PATCH|PURGE,default=GET"`
126+
Headers Headers `wst:"headers"`
127+
TLS TLSClientConfig `wst:"tls"`
122128
}
123129

124130
type BenchAction struct {

mocks/generated/app/mock_Foundation.go

Lines changed: 60 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/generated/app/mock_X509CertPool.go

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)