summaryrefslogtreecommitdiffstats
path: root/nat_auth/NATAuthTest.st
blob: 34b1b5a16f6c14f8aa4d7e04f06c2e8f56132689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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.
]