File: ntlm.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (92 lines) | stat: -rw-r--r-- 3,000 bytes parent folder | download | duplicates (5)
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
88
89
90
91
92
# sasl.test - Copyright (C) 2002 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# Tests for the Tcllib SASL package
#
# -------------------------------------------------------------------------
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -------------------------------------------------------------------------
# RCS: @(#) $Id: ntlm.test,v 1.5 2006/10/09 21:41:41 andreas_kupries Exp $

# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.2
testsNeedTcltest 1.0

support {
    use      base64/base64.tcl base64
    useLocal sasl.tcl          SASL
}
testing {
    useLocal ntlm.tcl SASL::NTLM
}

# -------------------------------------------------------------------------
# Tests
# -------------------------------------------------------------------------

proc NTLMCallback {context command args} {
    upvar #0 $context ctx
    switch -exact -- $command {
        login    { return "" }
        username { return "user" }
        password { return "SecREt01" }
        realm    { return DOMAIN }
        hostname { return WORKSTATION }
        default {
            return -code error "oops: client needs to write $command"
        }
    }
}

# -------------------------------------------------------------------------

#
# Sample NTLM messages from
# http://davenport.sf.net/ntlm.html: NTLM HTTP Authentication
#
variable Chk; array set Chk {}
set Chk(1) TlRMTVNTUAABAAAAByIAAAYABgArAAAACwALACAAAABXT1JLU1RBVElPTkRPTUFJTg==
set Chk(2) [join {TlRMTVNTUAACAAAADAAMADAAAAABAoEAASNFZ4mrze8
    AAAAAAAAAAGIAYgA8AAAARABPAE0AQQBJAE4AAgAMAEQATwBNAEEASQBOAAEADABTA
    EUAUgBWAEUAUgAEABQAZABvAG0AYQBpAG4ALgBjAG8AbQADACIAcwBlAHIAdgBlAHI
    ALgBkAG8AbQBhAGkAbgAuAGMAbwBtAAAAAAA=}]
set Chk(3) [join {TlRMTVNTUAADAAAAGAAYAGoAAAAYABgAggAAAAwADABAAAAACAAI
    AEwAAAAWABYAVAAAAAAAAACaAAAAAQKBAEQATwBNAEEASQBOAHUAcwBlAHIAVwBPAF
    IASwBTAFQAQQBUAEkATwBOAMM3zVy9RPyXgqZnr21CfG3mfCDC0+d8ViWpjBwx6BhH
    Rmspst9GgPOZWPuMITqcxg==} {}]

test SASL-NTLM-1.0 {NTLM client challenge} {
    list [catch {
        set ctx [SASL::new -mechanism NTLM -callback NTLMCallback]
        SASL::step $ctx ""
        set response [SASL::response $ctx]
        SASL::cleanup $ctx
        base64::encode -maxlen 0 $response
    } res] $res
} [list 0 $Chk(1)]

test SASL-NTLM-1.1 {NTLM client response} {
    list [catch {
        set ctx [SASL::new -mechanism NTLM -callback NTLMCallback]
        SASL::step $ctx ""
        SASL::step $ctx [base64::decode $Chk(2)]
        set response [SASL::response $ctx]
        SASL::cleanup $ctx
        base64::encode -maxlen 0 $response
    } res] $res
} [list 0 $Chk(3)]

# -------------------------------------------------------------------------

unset Chk
testsuiteCleanup

# Local Variables:
#  mode: tcl
#  indent-tabs-mode: nil
# End: