Backport of Committing for - 15055 into release/1.14.x (#15121)

This pull request was automerged via backport-assistant
pull/15124/head
hc-github-team-consul-core 2022-10-24 11:41:43 -04:00 committed by GitHub
parent 39aad746e9
commit 6530f515bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -197,7 +197,11 @@ func (c *FSM) Restore(old io.ReadCloser) error {
return err
}
default:
return fmt.Errorf("Unrecognized msg type %d", msg)
if msg >= 64 {
return fmt.Errorf("msg type <%d> is a Consul Enterprise log entry. Consul OSS cannot restore it", msg)
} else {
return fmt.Errorf("Unrecognized msg type %d", msg)
}
}
return nil
}

View File

@ -882,6 +882,34 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) {
default:
require.Fail(t, "Old state not abandoned")
}
// To verify if a proper message is displayed when Consul OSS tries to
// unsuccessfully restore entries from a Consul Ent snapshot.
buf = bytes.NewBuffer(nil)
sink = &MockSink{buf, false}
fsm, _ = New(nil, logger)
type EntMock struct {
ID int
Type string
}
entMockEntry := EntMock{
ID: 65,
Type: "A Consul Ent Log Type",
}
// Write the header
header := SnapshotHeader{
LastIndex: 0,
}
encoder = codec.NewEncoder(sink, structs.MsgpackHandle)
encoder.Encode(&header)
sink.Write([]byte{byte(structs.MessageType(entMockEntry.ID))})
encoder.Encode(entMockEntry)
require.EqualError(t, fsm.Restore(sink), "msg type <65> is a Consul Enterprise log entry. Consul OSS cannot restore it")
sink.Cancel()
}
// convertACLTokenToLegacy attempts to convert an ACLToken into an legacy ACL.