1
0
Fork 0

nat: Add a testcase for authentication to the nat

This commit is contained in:
Holger Hans Peter Freyther 2013-03-19 21:54:37 +01:00
parent 7b301d401b
commit 0c12e43d1e
3 changed files with 102 additions and 0 deletions

87
nat_auth/NATAuthTest.st Normal file
View File

@ -0,0 +1,87 @@
PackageLoader
fileInPackage: #OsmoNetwork;
fileInPackage: #SUnit.
TestCase subclass: NATAuthTest [
| socket demuxer mux queue |
<comment: 'I test the authentication/by-passing of auth on the NAT.'>
<import: Osmo>
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.
]

9
nat_auth/README Normal file
View File

@ -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.

View File

@ -0,0 +1,6 @@
nat
msc port 5002
bsc 0
token test
mgcp
call agent ip 127.0.0.1