From 0c12e43d1ef5173630b882c2a49e30f3a6413bff Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 19 Mar 2013 21:54:37 +0100 Subject: nat: Add a testcase for authentication to the nat --- nat_auth/NATAuthTest.st | 87 +++++++++++++++++++++++++++++++++++++++++++++++ nat_auth/README | 9 +++++ nat_auth/osmo-bsc_nat.cfg | 6 ++++ 3 files changed, 102 insertions(+) create mode 100644 nat_auth/NATAuthTest.st create mode 100644 nat_auth/README create mode 100644 nat_auth/osmo-bsc_nat.cfg diff --git a/nat_auth/NATAuthTest.st b/nat_auth/NATAuthTest.st new file mode 100644 index 0000000..34b1b5a --- /dev/null +++ b/nat_auth/NATAuthTest.st @@ -0,0 +1,87 @@ +PackageLoader + fileInPackage: #OsmoNetwork; + fileInPackage: #SUnit. + +TestCase subclass: NATAuthTest [ + | socket demuxer mux queue | + + + + connect [ + | msg | + + socket ifNotNil: [socket close]. + socket := Sockets.Socket remote: '127.0.0.1' port: 5000. + queue := SharedQueue new. + demuxer := IPADemuxer initOn: socket. + mux := IPAMuxer initOn: queue. + + "ID ACK" + msg := demuxer next. + self assert: msg = (Array with: 254 with: $<6> asString). + + "ID Req" + msg := demuxer next. + self assert: msg first = IPAConstants protocolIPA. + self assert: msg second first asInteger = IPAConstants msgIdGet. + + "RSIP for MGCP.." + msg := demuxer next. + self assert: msg first = IPAConstants protocolMGCP. + ] + + run [ + self + testByPass; + testShort. + ] + + verifyNotConnected [ + [ | msg | + msg := demuxer next. + self assert: false. + ] on: SystemExceptions.EndOfStream do: [^true]. + ] + + testByPass [ + | resp | + Transcript nextPutAll: 'Testing by-pass'; nl. + self connect. + + "Now construct a response.." + resp := MessageBuffer new + putByte: IPAConstants msgIdResp; + putLen16: 0; + putByte: IPAConstants idtagUnitName; + yourself. + mux nextPut: resp asByteArray with: IPAConstants protocolIPA. + socket nextPutAllFlush: queue next. + + self verifyNotConnected. + ] + + testShort [ + | resp | + Transcript nextPutAll: 'Testing short'; nl. + + self connect. + + "Now construct a short message..." + resp := MessageBuffer new + putByte: IPAConstants msgIdResp; + putLen16: 3; + putByte: IPAConstants idtagUnitName; + putByteArray: 'tes' asByteArray; + yourself. + mux nextPut: resp asByteArray with: IPAConstants protocolIPA. + socket nextPutAllFlush: queue next. + + self verifyNotConnected. + ] +] + +Eval [ + | test | + test := NATAuthTest new + run. +] diff --git a/nat_auth/README b/nat_auth/README new file mode 100644 index 0000000..89251a4 --- /dev/null +++ b/nat_auth/README @@ -0,0 +1,9 @@ +Some sanity checking with the auth.. + +1.) Listen on port 5002 +$ nc -l 5002 + +2.) Start the nat with local cfg file + +3.) Start the test. + diff --git a/nat_auth/osmo-bsc_nat.cfg b/nat_auth/osmo-bsc_nat.cfg new file mode 100644 index 0000000..a159414 --- /dev/null +++ b/nat_auth/osmo-bsc_nat.cfg @@ -0,0 +1,6 @@ +nat + msc port 5002 +bsc 0 + token test +mgcp + call agent ip 127.0.0.1 -- cgit v1.2.3