Skip to content

Commit

Permalink
Merge pull request #557 from twmb/fix_tcp_https_opt
Browse files Browse the repository at this point in the history
nsqd: fix -tls-required=tcp-https with -tls-client-auth-policy
  • Loading branch information
mreiferson committed Mar 12, 2015
2 parents 1362b8e + adc73d4 commit 831c218
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions nsqd/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,36 @@ func TestHTTPSRequireVerify(t *testing.T) {
equal(t, topic.Depth(), int64(1))
}

func TestTLSRequireVerifyExceptHTTP(t *testing.T) {
opts := NewNSQDOptions()
opts.Logger = newTestLogger(t)
opts.Verbose = true
opts.TLSCert = "./test/certs/server.pem"
opts.TLSKey = "./test/certs/server.key"
opts.TLSRootCAFile = "./test/certs/ca.pem"
opts.TLSClientAuthPolicy = "require-verify"
opts.TLSRequired = TLSRequiredExceptHTTP
_, httpAddr, nsqd := mustStartNSQD(opts)

defer nsqd.Exit()

topicName := "test_http_req_verf_except_http" + strconv.Itoa(int(time.Now().Unix()))
topic := nsqd.GetTopic(topicName)

// no cert
buf := bytes.NewBuffer([]byte("test message"))
url := fmt.Sprintf("http://%s/put?topic=%s", httpAddr, topicName)
resp, err := http.Post(url, "application/octet-stream", buf)
equal(t, err, nil)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
equal(t, string(body), "OK")

time.Sleep(5 * time.Millisecond)

equal(t, topic.Depth(), int64(1))
}

func TestHTTPDeprecatedTopicChannel(t *testing.T) {
opts := NewNSQDOptions()
opts.Logger = newTestLogger(t)
Expand Down
2 changes: 1 addition & 1 deletion nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func NewNSQD(opts *nsqdOptions) *NSQD {
opts.StatsdPrefix = prefixWithHost
}

if opts.TLSClientAuthPolicy != "" {
if opts.TLSClientAuthPolicy != "" && opts.TLSRequired == TLSNotRequired {
opts.TLSRequired = TLSRequired
}

Expand Down

0 comments on commit 831c218

Please sign in to comment.