mirror of https://github.com/hashicorp/consul
agent: use testing intention to get valid intentions
parent
ab4ea3efb4
commit
70858598e4
|
@ -99,9 +99,12 @@ func (s *Intention) Apply(
|
||||||
args.Intention.DestinationNS = structs.IntentionDefaultNamespace
|
args.Intention.DestinationNS = structs.IntentionDefaultNamespace
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate
|
// Validate. We do not validate on delete since it is valid to only
|
||||||
if err := args.Intention.Validate(); err != nil {
|
// send an ID in that case.
|
||||||
return err
|
if args.Op != structs.IntentionOpDelete {
|
||||||
|
if err := args.Intention.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit
|
// Commit
|
||||||
|
|
|
@ -173,7 +173,13 @@ func (s *HTTPServer) IntentionSpecificGet(id string, resp http.ResponseWriter, r
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: validate length
|
// This shouldn't happen since the called API documents it shouldn't,
|
||||||
|
// but we check since the alternative if it happens is a panic.
|
||||||
|
if len(reply.Intentions) == 0 {
|
||||||
|
resp.WriteHeader(http.StatusNotFound)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
return reply.Intentions[0], nil
|
return reply.Intentions[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,10 @@ func TestIntentionsList_values(t *testing.T) {
|
||||||
req := structs.IntentionRequest{
|
req := structs.IntentionRequest{
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
Op: structs.IntentionOpCreate,
|
Op: structs.IntentionOpCreate,
|
||||||
Intention: &structs.Intention{SourceName: v},
|
Intention: structs.TestIntention(t),
|
||||||
}
|
}
|
||||||
|
req.Intention.SourceName = v
|
||||||
|
|
||||||
var reply string
|
var reply string
|
||||||
if err := a.RPC("Intention.Apply", &req, &reply); err != nil {
|
if err := a.RPC("Intention.Apply", &req, &reply); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
|
@ -93,13 +95,10 @@ func TestIntentionsMatch_basic(t *testing.T) {
|
||||||
ixn := structs.IntentionRequest{
|
ixn := structs.IntentionRequest{
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
Op: structs.IntentionOpCreate,
|
Op: structs.IntentionOpCreate,
|
||||||
Intention: &structs.Intention{
|
Intention: structs.TestIntention(t),
|
||||||
SourceNS: "default",
|
|
||||||
SourceName: "test",
|
|
||||||
DestinationNS: v[0],
|
|
||||||
DestinationName: v[1],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
ixn.Intention.DestinationNS = v[0]
|
||||||
|
ixn.Intention.DestinationName = v[1]
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
var reply string
|
var reply string
|
||||||
|
@ -198,7 +197,8 @@ func TestIntentionsCreate_good(t *testing.T) {
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
// Make sure an empty list is non-nil.
|
// Make sure an empty list is non-nil.
|
||||||
args := &structs.Intention{SourceName: "foo"}
|
args := structs.TestIntention(t)
|
||||||
|
args.SourceName = "foo"
|
||||||
req, _ := http.NewRequest("POST", "/v1/connect/intentions", jsonReader(args))
|
req, _ := http.NewRequest("POST", "/v1/connect/intentions", jsonReader(args))
|
||||||
resp := httptest.NewRecorder()
|
resp := httptest.NewRecorder()
|
||||||
obj, err := a.srv.IntentionCreate(resp, req)
|
obj, err := a.srv.IntentionCreate(resp, req)
|
||||||
|
@ -238,12 +238,7 @@ func TestIntentionsSpecificGet_good(t *testing.T) {
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
// The intention
|
// The intention
|
||||||
ixn := &structs.Intention{
|
ixn := structs.TestIntention(t)
|
||||||
SourceNS: structs.IntentionDefaultNamespace,
|
|
||||||
SourceName: "foo",
|
|
||||||
DestinationNS: structs.IntentionDefaultNamespace,
|
|
||||||
DestinationName: "bar",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create an intention directly
|
// Create an intention directly
|
||||||
var reply string
|
var reply string
|
||||||
|
@ -286,7 +281,7 @@ func TestIntentionsSpecificUpdate_good(t *testing.T) {
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
// The intention
|
// The intention
|
||||||
ixn := &structs.Intention{SourceName: "foo"}
|
ixn := structs.TestIntention(t)
|
||||||
|
|
||||||
// Create an intention directly
|
// Create an intention directly
|
||||||
var reply string
|
var reply string
|
||||||
|
@ -341,7 +336,8 @@ func TestIntentionsSpecificDelete_good(t *testing.T) {
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
// The intention
|
// The intention
|
||||||
ixn := &structs.Intention{SourceName: "foo"}
|
ixn := structs.TestIntention(t)
|
||||||
|
ixn.SourceName = "foo"
|
||||||
|
|
||||||
// Create an intention directly
|
// Create an intention directly
|
||||||
var reply string
|
var reply string
|
||||||
|
|
|
@ -13,5 +13,6 @@ func TestIntention(t testing.T) *Intention {
|
||||||
DestinationName: "db",
|
DestinationName: "db",
|
||||||
Action: IntentionActionAllow,
|
Action: IntentionActionAllow,
|
||||||
SourceType: IntentionSourceConsul,
|
SourceType: IntentionSourceConsul,
|
||||||
|
Meta: map[string]string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue