mirror of
https://github.com/bolkedebruin/rdpgw.git
synced 2025-08-17 22:13:50 +02:00
Add tests WIP
This commit is contained in:
parent
7bace85c15
commit
bfe300c3dc
4 changed files with 93 additions and 1 deletions
46
protocol/client.go
Normal file
46
protocol/client.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
const (
|
||||
MajorVersion = 0x0
|
||||
MinorVersion = 0x0
|
||||
Version = 0x00
|
||||
)
|
||||
|
||||
type ClientConfig struct {
|
||||
SmartCardAuth bool
|
||||
PAAToken string
|
||||
NTLMAuth bool
|
||||
}
|
||||
|
||||
func (c *ClientConfig) handshakeRequest() []byte {
|
||||
var caps uint16
|
||||
|
||||
if c.SmartCardAuth {
|
||||
caps = caps | HTTP_EXTENDED_AUTH_SC
|
||||
}
|
||||
|
||||
if len(c.PAAToken) > 0 {
|
||||
caps = caps | HTTP_EXTENDED_AUTH_PAA
|
||||
}
|
||||
|
||||
if c.NTLMAuth {
|
||||
caps = caps | HTTP_EXTENDED_AUTH_SSPI_NTLM
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
binary.Write(buf, binary.LittleEndian, byte(MajorVersion))
|
||||
binary.Write(buf, binary.LittleEndian, byte(MinorVersion))
|
||||
binary.Write(buf, binary.LittleEndian, uint16(Version))
|
||||
|
||||
binary.Write(buf, binary.LittleEndian, uint16(caps))
|
||||
|
||||
return createPacket(PKT_TYPE_HANDSHAKE_REQUEST, buf.Bytes())
|
||||
}
|
||||
|
||||
func (c *ClientConfig) readServerHandshakeResponse(data []byte) ()
|
|
@ -225,7 +225,7 @@ func (h *Handler) ReadMessage() (pt int, n int, msg []byte, err error) {
|
|||
func (h *Handler) handshakeResponse(major byte, minor byte) []byte {
|
||||
var caps uint16
|
||||
if h.SmartCardAuth {
|
||||
caps = caps | HTTP_EXTENDED_AUTH_PAA
|
||||
caps = caps | HTTP_EXTENDED_AUTH_SC
|
||||
}
|
||||
if h.TokenAuth {
|
||||
caps = caps | HTTP_EXTENDED_AUTH_PAA
|
||||
|
|
44
protocol/handler_test.go
Normal file
44
protocol/handler_test.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
HeaderLen = 8
|
||||
HandshakeRequestLen = HeaderLen + 6
|
||||
)
|
||||
|
||||
func TestHandshake(t *testing.T) {
|
||||
client := ClientConfig{
|
||||
PAAToken: "abab",
|
||||
}
|
||||
|
||||
data := client.handshakeRequest()
|
||||
pt, size, pkt, err := readHeader(data)
|
||||
|
||||
if pt != PKT_TYPE_HANDSHAKE_REQUEST {
|
||||
t.Fatalf("readHeader failed, expected packet type %d got %d", PKT_TYPE_HANDSHAKE_REQUEST, pt)
|
||||
}
|
||||
|
||||
if size != HandshakeRequestLen {
|
||||
t.Fatalf("readHeader failed, expected size %d, got %d", HandshakeRequestLen, size)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("readHeader failed got error %s", err)
|
||||
}
|
||||
|
||||
log.Printf("pkt: %x", pkt)
|
||||
|
||||
major, minor, version, extAuth := readHandshake(pkt)
|
||||
if major != MajorVersion || minor != MinorVersion || version != Version {
|
||||
t.Fatalf("readHandshake failed got version %d.%d protocol %d, expected %d.%d protocol %d",
|
||||
major, minor, version, MajorVersion, MinorVersion, Version)
|
||||
}
|
||||
|
||||
if !((extAuth & HTTP_EXTENDED_AUTH_PAA) == HTTP_EXTENDED_AUTH_PAA) {
|
||||
t.Fatalf("readHandshake failed got ext auth %d, expected %d", extAuth, extAuth | HTTP_EXTENDED_AUTH_PAA)
|
||||
}
|
||||
}
|
2
protocol/rdpgw_test.go
Normal file
2
protocol/rdpgw_test.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package protocol
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue