forked from node-pcap/node_pcap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
var Arp = require("../../decode/arp"); | ||
var events = require("events"); | ||
var shouldBehaveLikeADecoder = require("./decode").shouldBehaveLikeADecoder; | ||
require("should"); | ||
|
||
describe("Arp", function(){ | ||
beforeEach(function () { | ||
this.eventEmitter = new events.EventEmitter(); | ||
this.instance = new Arp(this.eventEmitter); | ||
this.example = new Buffer("0001" + | ||
"0800060400010007" + | ||
"0daff454454cd801" + | ||
"000000000000454c" + | ||
"dfd5", "hex"); | ||
}); | ||
|
||
describe("#decode()", function(){ | ||
shouldBehaveLikeADecoder("arp", true); | ||
|
||
it("sets #htype to the hardware type", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("htype", 1); // Ethernet | ||
}); | ||
|
||
it("sets #ptype to the protocol type", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("ptype", 0x0800); // IP | ||
}); | ||
|
||
it("sets #hlen to the hardware size", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("hlen", 6); | ||
}); | ||
|
||
it("sets #plen to the protocol size", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("plen", 4); | ||
}); | ||
|
||
it("sets #operation to the operation code", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.should.have.property("operation", 1); | ||
}); | ||
|
||
it("sets #sender_ha to the sender's MAC", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.sender_ha.should.have.property("addr", [0x00, 0x07, 0x0d, 0xaf, 0xf4, 0x54]); | ||
}); | ||
|
||
it("sets #sender_pa to the sender's protocol address", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.sender_pa.should.have.property("addr", [69, 76, 216, 1]); | ||
}); | ||
|
||
it("sets #target_ha to the target's MAC", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.target_ha.should.have.property("addr", [0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); | ||
}); | ||
|
||
it("sets #target_pa to the sender's protocol address", function () { | ||
this.instance.decode(this.example, 0); | ||
this.instance.target_pa.should.have.property("addr", [69, 76, 223, 213]); | ||
}); | ||
}); | ||
|
||
describe("#toString()", function(){ | ||
it("is a function", function(){ | ||
this.instance.toString.should.be.type("function"); | ||
}); | ||
|
||
it("returns a value like request sender 00:07:0d:af:f4:54 69.76.216.1 target 00:00:00:00:00:00 69.76.223.213", function() { | ||
this.instance.decode(this.example, 0); | ||
this.instance.toString().should.be.exactly("request sender 00:07:0d:af:f4:54 69.76.216.1 target 00:00:00:00:00:00 69.76.223.213"); | ||
}); | ||
}); | ||
}); |