opentofu/internal/backend/remote-state/http/mock_server_test.go

96 lines
3.2 KiB
Go
Raw Normal View History

[fixes 31700] Add mTLS support for http backend by way of client cert & key, as well as enterprise cacert. (#31699) * Add mTLS support for http backend by way of client cert & key, as well as enterprise cacert. * Fix style. * Skip cert validation to be sure error is related to missing client cert; not untrusted server cert. * Remove misplaced err check. * Fix the size of test using http backend. * Just for correctness, include all certs in the pem encoded cert - sometimes certs come with a chain of their signers. * Adjusted names as recommended in PR comments. * Adjusted names to be full-length and more descriptive. * Added full-fledged testing with mTLS http server * Fix goimports. * Fix the names of the backend config. * Exclusive lock for write and delete. * Revert "Fix goimports." This reverts commit 7d40f6099fbbb675fb2e25e35ee40aeafe3d0a22. * goimports just for server test. * Added the go:generation for the mock. * Move the TLS configuration out to make it more readable - don't replace the HTTPClient as the retryablehttp already creates one - just configure its TLS. * Just switch the client/data params - felt more natural this way. * Update internal/backend/remote-state/http/backend.go Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com> * Update internal/backend/remote-state/http/testdata/gencerts.sh Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com> * Update internal/backend/remote-state/http/backend.go Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com> * Update internal/backend/remote-state/http/backend.go Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com> * Update internal/backend/remote-state/http/backend.go Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com> * Update internal/backend/remote-state/http/backend.go Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com> * the location of the file name is not sensitive. * Added error if only one of client_certificate_pem and client_private_key_pem are set. * Remove testify from test cases; use t.Error* for assert and t.Fatal* for require. * Fixed import consistency * Just use default openssl. * Since file(...) is so trivial to use, changed the client cert, key, and ca cert to be the data. See also https://github.com/hashicorp/terraform-provider-http/pull/211 Co-authored-by: Sheridan C Rawlins <scr@ouryahoo.com> Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2023-01-26 08:08:07 -06:00
// Code generated by MockGen. DO NOT EDIT.
// Source: server_test.go
// Package http is a generated GoMock package.
package http
import (
http "net/http"
reflect "reflect"
gomock "github.com/golang/mock/gomock"
)
// MockHttpServerCallback is a mock of HttpServerCallback interface.
type MockHttpServerCallback struct {
ctrl *gomock.Controller
recorder *MockHttpServerCallbackMockRecorder
}
// MockHttpServerCallbackMockRecorder is the mock recorder for MockHttpServerCallback.
type MockHttpServerCallbackMockRecorder struct {
mock *MockHttpServerCallback
}
// NewMockHttpServerCallback creates a new mock instance.
func NewMockHttpServerCallback(ctrl *gomock.Controller) *MockHttpServerCallback {
mock := &MockHttpServerCallback{ctrl: ctrl}
mock.recorder = &MockHttpServerCallbackMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockHttpServerCallback) EXPECT() *MockHttpServerCallbackMockRecorder {
return m.recorder
}
// StateDELETE mocks base method.
func (m *MockHttpServerCallback) StateDELETE(req *http.Request) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StateDELETE", req)
}
// StateDELETE indicates an expected call of StateDELETE.
func (mr *MockHttpServerCallbackMockRecorder) StateDELETE(req interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateDELETE", reflect.TypeOf((*MockHttpServerCallback)(nil).StateDELETE), req)
}
// StateGET mocks base method.
func (m *MockHttpServerCallback) StateGET(req *http.Request) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StateGET", req)
}
// StateGET indicates an expected call of StateGET.
func (mr *MockHttpServerCallbackMockRecorder) StateGET(req interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGET", reflect.TypeOf((*MockHttpServerCallback)(nil).StateGET), req)
}
// StateLOCK mocks base method.
func (m *MockHttpServerCallback) StateLOCK(req *http.Request) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StateLOCK", req)
}
// StateLOCK indicates an expected call of StateLOCK.
func (mr *MockHttpServerCallbackMockRecorder) StateLOCK(req interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateLOCK", reflect.TypeOf((*MockHttpServerCallback)(nil).StateLOCK), req)
}
// StatePOST mocks base method.
func (m *MockHttpServerCallback) StatePOST(req *http.Request) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StatePOST", req)
}
// StatePOST indicates an expected call of StatePOST.
func (mr *MockHttpServerCallbackMockRecorder) StatePOST(req interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StatePOST", reflect.TypeOf((*MockHttpServerCallback)(nil).StatePOST), req)
}
// StateUNLOCK mocks base method.
func (m *MockHttpServerCallback) StateUNLOCK(req *http.Request) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "StateUNLOCK", req)
}
// StateUNLOCK indicates an expected call of StateUNLOCK.
func (mr *MockHttpServerCallbackMockRecorder) StateUNLOCK(req interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateUNLOCK", reflect.TypeOf((*MockHttpServerCallback)(nil).StateUNLOCK), req)
}