test: move some test helpers over from enterprise (#7754)
This commit is contained in:
parent
5848f0fd7b
commit
4a630135b8
|
@ -1046,7 +1046,7 @@ func (s *HTTPServer) ACLLogin(resp http.ResponseWriter, req *http.Request) (inte
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.rewordUnknownEnterpriseFieldError(lib.DecodeJSON(req.Body, &args.Auth)); err != nil {
|
if err := s.rewordUnknownEnterpriseFieldError(lib.DecodeJSON(req.Body, &args.Auth)); err != nil {
|
||||||
return nil, BadRequestError{Reason: fmt.Sprintf("Failed to decode request body:: %v", err)}
|
return nil, BadRequestError{Reason: fmt.Sprintf("Failed to decode request body: %v", err)}
|
||||||
}
|
}
|
||||||
|
|
||||||
var out structs.ACLToken
|
var out structs.ACLToken
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/hashicorp/consul/agent/consul/authmethod/testauth"
|
"github.com/hashicorp/consul/agent/consul/authmethod/testauth"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
"github.com/hashicorp/consul/testrpc"
|
"github.com/hashicorp/consul/testrpc"
|
||||||
|
"github.com/hashicorp/go-uuid"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2031,3 +2032,58 @@ func TestACL_Authorize(t *testing.T) {
|
||||||
require.Nil(t, raw)
|
require.Nil(t, raw)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type rpcFn func(string, interface{}, interface{}) error
|
||||||
|
|
||||||
|
func upsertTestCustomizedAuthMethod(
|
||||||
|
rpc rpcFn, masterToken string, datacenter string,
|
||||||
|
modify func(method *structs.ACLAuthMethod),
|
||||||
|
) (*structs.ACLAuthMethod, error) {
|
||||||
|
name, err := uuid.GenerateUUID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req := structs.ACLAuthMethodSetRequest{
|
||||||
|
Datacenter: datacenter,
|
||||||
|
AuthMethod: structs.ACLAuthMethod{
|
||||||
|
Name: "test-method-" + name,
|
||||||
|
Type: "testing",
|
||||||
|
},
|
||||||
|
WriteRequest: structs.WriteRequest{Token: masterToken},
|
||||||
|
}
|
||||||
|
|
||||||
|
if modify != nil {
|
||||||
|
modify(&req.AuthMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
var out structs.ACLAuthMethod
|
||||||
|
|
||||||
|
err = rpc("ACL.AuthMethodSet", &req, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func upsertTestCustomizedBindingRule(rpc rpcFn, masterToken string, datacenter string, modify func(rule *structs.ACLBindingRule)) (*structs.ACLBindingRule, error) {
|
||||||
|
req := structs.ACLBindingRuleSetRequest{
|
||||||
|
Datacenter: datacenter,
|
||||||
|
BindingRule: structs.ACLBindingRule{},
|
||||||
|
WriteRequest: structs.WriteRequest{Token: masterToken},
|
||||||
|
}
|
||||||
|
|
||||||
|
if modify != nil {
|
||||||
|
modify(&req.BindingRule)
|
||||||
|
}
|
||||||
|
|
||||||
|
var out structs.ACLBindingRule
|
||||||
|
|
||||||
|
err := rpc("ACL.BindingRuleSet", &req, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue