Exemplo n.º 1
0
func TestNTLMHTTPClient(t *testing.T) {
	// TODO: combine client and server tests so we don't need external server
	if len(*testURL) == 0 {
		t.Skip("Skipping due to empty \"url\" parameter")
	}

	cred, err := ntlm.AcquireCurrentUserCredentials()
	if err != nil {
		t.Fatal(err)
	}
	defer cred.Release()

	secctx, negotiate, err := ntlm.NewClientContext(cred)
	if err != nil {
		t.Fatal(err)
	}
	defer secctx.Release()

	err = canDoNTLM()
	if err != nil {
		t.Fatal(err)
	}
	challenge, err := doNTLMNegotiate(negotiate)
	if err != nil {
		t.Fatal(err)
	}
	authenticate, err := secctx.Update(challenge)
	if err != nil {
		t.Fatal(err)
	}
	_, err = doNTLMAuthenticate(authenticate)
	if err != nil {
		t.Fatal(err)
	}
}
Exemplo n.º 2
0
func testNTLM(t *testing.T, clientCred *sspi.Credentials) {
	serverCred, err := ntlm.AcquireServerCredentials()
	if err != nil {
		t.Fatal(err)
	}
	defer serverCred.Release()

	client, token1, err := ntlm.NewClientContext(clientCred)
	if err != nil {
		t.Fatal(err)
	}
	defer client.Release()

	testContextExpiry(t, "clent security context", client)

	server, token2, err := ntlm.NewServerContext(serverCred, token1)
	if err != nil {
		t.Fatal(err)
	}
	defer server.Release()

	testContextExpiry(t, "server security context", server)

	token3, err := client.Update(token2)
	if err != nil {
		t.Fatal(err)
	}

	err = server.Update(token3)
	if err != nil {
		t.Fatal(err)
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	err = server.ImpersonateUser()
	if err != nil {
		t.Fatal(err)
	}
	defer server.RevertToSelf()

	_, err = user.Current()
	if err != nil {
		t.Fatal(err)
	}
}