summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.cpp
blob: aae0205c1f28eef09154b0d2d167638344eac88d (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "clientstream_test.h"

ClientStreamTest::ClientStreamTest(int argc, char ** argv) : TQApplication( argc, argv )
{
	// set up client stream
	myConnector = new KNetworkConnector( 0 );
	//myConnector->setOptHostPort( "localhost", 8300 );
	myConnector->setOptHostPort( "reiser.suse.de", 8300 );
	myConnector->setOptSSL( true );
	Q_ASSERT( TQCA::isSupported(TQCA::CAP_TLS) );
	myTLS = new TQCA::TLS;
	myTLSHandler = new TQCATLSHandler( myTLS );
	myTestObject = new ClientStream( myConnector, myTLSHandler, 0);
	// notify when the transport layer is connected
	connect( myTestObject, TQT_SIGNAL( connected() ), TQT_SLOT( slotConnected() ) );
	// it's necessary to catch this signal and tell the TLS handler to proceed, even if we don't check cert validity
	connect( myTLSHandler, TQT_SIGNAL(tlsHandshaken()), TQT_SLOT(slotTLSHandshaken()) );
	// notify and start sending
	connect( myTestObject, TQT_SIGNAL( securityLayerActivated(int) ), TQT_SLOT( slotSend(int) ) );
	connect( myTestObject, TQT_SIGNAL( warning(int) ), TQT_SLOT( slotWarning(int) ) );

	// do test once the event loop is running
	TQTimer::singleShot( 0, this, TQT_SLOT( slotDoTest() ) );
}

ClientStreamTest::~ClientStreamTest()
{
	delete myTestObject;
	delete myTLSHandler;
	delete myTLS;
	delete myConnector;
}

void ClientStreamTest::slotDoTest()
{
	NovellDN dn;
	dn.dn = "maeuschen";
	dn.server = "reiser.suse.de";
	// connect to server
	tqDebug( "connecting to server ");
	myTestObject->connectToServer( dn, true ); // fine up to here...
}

void ClientStreamTest::slotConnected()
{
	tqDebug( "connection is up");
}

void ClientStreamTest::slotWarning(int warning)
{
	tqDebug( "warning: %i", warning);
}

void ClientStreamTest::slotsend(int layer)
{
	tqDebug( "security layer is up: %i", layer);
	RequestFactory testFactory;
	// we're not connecting...
	tqDebug( "sending request" );
	// send a request
	TQCString command("login");
	Request * firstRequest = testFactory.request( command );
	Field::FieldList lst;
	lst.append( new Field::SingleField( NM_A_SZ_USERID, 0, NMFIELD_TYPE_UTF8, "maeuschen" ) );
	lst.append( new Field::SingleField( NM_A_SZ_CREDENTIALS, 0, NMFIELD_TYPE_UTF8, "maeuschen" ) );
	lst.append( new Field::SingleField( NM_A_SZ_USER_AGENT, 0, NMFIELD_TYPE_UTF8, "libgroupwise/0.1 (linux, 2.6.5-7.97-smp)" ) );
	lst.append( new Field::SingleField( NM_A_UD_BUILD, 0, NMFIELD_TYPE_UDWORD, 2 ) );
	lst.append( new Field::SingleField( NM_A_IP_ADDRESS, 0, NMFIELD_TYPE_UTF8, "10.10.11.103" ) );
	firstRequest->setFields( lst );
	myTestObject->write( firstRequest );
	tqDebug( "done");
}
	
void ClientStreamTest::slotTLSHandshaken()
{
	tqDebug( "TLS handshake complete" );
	int validityResult = myTLS->certificateValidityResult ();

	if( validityResult == TQCA::TLS::Valid )
	{
		tqDebug( "Certificate is valid, continuing.");
		// valid certificate, continue
		myTLSHandler->continueAfterHandshake ();
	}
	else
	{
		tqDebug( "Certificate is not valid, continuing" );
		// certificate is not valid, query the user
		/*			if(handleTLSWarning (validityResult, server (), myself()->contactId ()) == KMessageBox::Continue)
					{*/
		myTLSHandler->continueAfterHandshake ();
		/*			}
					else
					{
					disconnect ( Kopete::Account::Manual );
					}*/
	}

}
int main(int argc, char ** argv)
{
	ClientStreamTest a( argc, argv );
	a.exec();
	return 0;
}

#include "clientstream_test.moc"