Skip to content

Commit

Permalink
Ensure start epoch of KeyLookupInEpoch and Monitoring requests is in PAD
Browse files Browse the repository at this point in the history
- Otherwise directory.LookupInEpoch() fails with ErrorDirectory, though a start epoch that is > the latest epoch indicates a malformed client message.
- Closes #108
  • Loading branch information
masomel committed Oct 25, 2016
1 parent ff9d71e commit 058c6fd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
7 changes: 5 additions & 2 deletions protocol/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ func (d *ConiksDirectory) HandleOps(req *Request) (*Response, ErrorCode) {
}
case KeyLookupInEpochType:
if msg, ok := req.Request.(*KeyLookupInEpochRequest); ok {
if len(msg.Username) > 0 {
if len(msg.Username) > 0 &&
msg.Epoch <= d.LatestSTR().Epoch {
return d.KeyLookupInEpoch(msg)
}
}
case MonitoringType:
if msg, ok := req.Request.(*MonitoringRequest); ok {
if len(msg.Username) > 0 && msg.StartEpoch <= msg.EndEpoch {
if len(msg.Username) > 0 &&
msg.StartEpoch <= d.LatestSTR().Epoch &&
msg.StartEpoch <= msg.EndEpoch {
return d.Monitor(msg)
}
}
Expand Down
44 changes: 41 additions & 3 deletions protocol/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,56 @@ func TestDirectoryKeyLookupInEpoch(t *testing.T) {
}
}

func TestHandleOps(t *testing.T) {
func TestDirectoryKeyLookupInEpochBadEpoch(t *testing.T) {
N := 3

d, _ := NewTestDirectory(t, false)
for i := 0; i < N; i++ {
d.Update()
}

// Send an invalid KeyLookupInEpochRequest (epoch > d.LatestEpoch())
// Expect ErrorMalformedClientMessage
req := &Request{
Type: KeyLookupInEpochType,
Request: &KeyLookupInEpochRequest{"alice", uint64(6)},
}

_, err := d.HandleOps(req)
if err != ErrorMalformedClientMessage {
t.Fatal("Expect error", ErrorMalformedClientMessage, "got", err)
}
}

func TestMonitoringBadStartEpoch(t *testing.T) {
N := 3

d, _ := NewTestDirectory(t, false)
// Send an invalid KeyLookupInEpochRequest
for i := 0; i < N; i++ {
d.Update()
}

// Send an invalid MonitoringRequest (startEpoch > d.LatestEpoch())
// Expect ErrorMalformedClientMessage
req := &Request{
Type: MonitoringType,
Request: &MonitoringRequest{"alice", uint64(2), uint64(0)},
Request: &MonitoringRequest{"alice", uint64(6), uint64(10)},
}
_, err := d.HandleOps(req)
if err != ErrorMalformedClientMessage {
t.Fatal("Expect error", ErrorMalformedClientMessage, "got", err)
}

// Send an invalid MonitoringRequest (startEpoch > EndEpoch)
// Expect ErrorMalformedClientMessage
req = &Request{
Type: MonitoringType,
Request: &MonitoringRequest{"alice", uint64(2), uint64(0)},
}
_, err = d.HandleOps(req)
if err != ErrorMalformedClientMessage {
t.Fatal("Expect error", ErrorMalformedClientMessage, "got", err)
}
}

func TestPoliciesChanges(t *testing.T) {
Expand Down

0 comments on commit 058c6fd

Please sign in to comment.