mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
Added validation of ServiceMeta in Catalog
Fixed Error Message when ServiceMeta is not valid Added Unit test for adding a Service with badly formatted ServiceMeta
This commit is contained in:
parent
6022c7a209
commit
980189a33f
@ -581,7 +581,7 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re
|
||||
ns := args.NodeService()
|
||||
if err := structs.ValidateMetadata(ns.ServiceMeta, false); err != nil {
|
||||
resp.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprint(resp, fmt.Errorf("Invalid Meta: %v", err))
|
||||
fmt.Fprint(resp, fmt.Errorf("Invalid Service Meta: %v", err))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
@ -610,6 +610,9 @@ func (s *Store) ensureServiceTxn(tx *memdb.Txn, idx uint64, node string, svc *st
|
||||
return fmt.Errorf("failed service lookup: %s", err)
|
||||
}
|
||||
|
||||
if err = structs.ValidateMetadata(svc.ServiceMeta, false); err != nil {
|
||||
return fmt.Errorf("Invalid Service Meta for node %s and serviceID %s: %v", node, svc.ID, err)
|
||||
}
|
||||
// Create the service node entry and populate the indexes. Note that
|
||||
// conversion doesn't populate any of the node-specific information.
|
||||
// That's always populated when we read from the state store.
|
||||
|
@ -69,6 +69,19 @@ func TestStateStore_EnsureRegistration(t *testing.T) {
|
||||
}
|
||||
verifyNode()
|
||||
|
||||
// Add in a invalid service definition with too long Key value for ServiceMeta
|
||||
req.Service = &structs.NodeService{
|
||||
ID: "redis1",
|
||||
Service: "redis",
|
||||
Address: "1.1.1.1",
|
||||
Port: 8080,
|
||||
ServiceMeta: map[string]string{strings.Repeat("a", 129): "somevalue"},
|
||||
Tags: []string{"master"},
|
||||
}
|
||||
if err := s.EnsureRegistration(9, req); err == nil {
|
||||
t.Fatalf("Service should not have been registered since ServiceMeta is invalid")
|
||||
}
|
||||
|
||||
// Add in a service definition.
|
||||
req.Service = &structs.NodeService{
|
||||
ID: "redis1",
|
||||
|
Loading…
x
Reference in New Issue
Block a user