#
#  PRE: if
#
string result_string
octets result_octets

#
#  over-write the existing User-Name
#
User-Name := 'EXAMPLE\bob'

# MS CHAPv1
request += {
	Vendor-Specific.Microsoft.CHAP-Challenge = 0xe96e4fff2955c4f1
	Vendor-Specific.Microsoft.CHAP-Response = 0x00010000000000000000000000000000000000000000000000008860bbaac0cd3960b4ce5dc6f0f7a462b897ef530484e80f
}

result_octets := %mschap(Challenge)
if !(result_octets == 0xe96e4fff2955c4f1) {
	test_fail
}

result_octets := %mschap(NT-Response)
if !(result_octets == 0x8860bbaac0cd3960b4ce5dc6f0f7a462b897ef530484e80f) {
	test_fail
}

result_string := %mschap(NT-Domain)
if !(result_string == 'EXAMPLE') {
	test_fail
}

result_string := %mschap(User-Name)
if !(result_string == 'bob') {
	test_fail
}

request.Vendor-Specific.Microsoft.CHAP-Response := 0x00006937d7935bb28a4c1dafe6a193bdea7a853a74d8bcf6db158860bbaac0cd3960b4ce5dc6f0f7a462b897ef530484e80f

result_octets := %mschap(LM-Response)

if !(result_octets == 0x6937d7935bb28a4c1dafe6a193bdea7a853a74d8bcf6db15) {
	test_fail
}

# Hashing
result_octets := %mschap(NT-Hash, 'testing_123')
if !(result_octets == 0xfa782604f85eb3564f555648341b53e4) {
	test_fail
}

result_octets := %mschap(LM-Hash, 'testing_123')
if !(result_octets == 0x2d5545077d7b7d2ae4343f96ab15c596) {
	test_fail
}

# MS CHAPv2
request -= Vendor-Specific.Microsoft.CHAP-Response[*]

Vendor-Specific.Microsoft.CHAP-Challenge := 0x04408dc2a98dae1ce351dfc53f57d08e
Vendor-Specific.Microsoft.CHAP2-Response := 0x00010e93cfbfcef8d5b6af42d2b2ca5b43180000000000000000bc068d1e8c54de5e9db78e6736d686eb88a999dd7fa239b200

result_octets := %mschap(Challenge)
if !(result_octets == 0xad18b6b8e1478b4c) {
	test_fail
}

result_octets := %mschap(NT-Response)
if !(result_octets == 0xbc068d1e8c54de5e9db78e6736d686eb88a999dd7fa239b2) {
	test_fail
}

# Invalid
Vendor-Specific.Microsoft.CHAP-Challenge := 0xf0eac4151d5346662ba8c5e428
result_string := %mschap(Challenge)

if (result_string) {
	test_fail
}

if (!(Module-Failure-Message == "Invalid MS-CHAP challenge length")) {
	test_fail
}

success
