summaryrefslogtreecommitdiff
path: root/cs/test/IceSSL/configuration/TestI.cs
blob: 2cc2f3e6ed98277013c3cd11b61267a2c254c233 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

using Test;
using System;
using System.Collections;

internal sealed class ServerI : ServerDisp_
{
    internal ServerI(Ice.Communicator communicator)
    {
	communicator_ = communicator;
    }

    public override void
    noCert(Ice.Current current)
    {
	try
	{
	    IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con);
	    test(info.certs == null);
	}
	catch(IceSSL.ConnectionInvalidException)
	{
	    test(false);
	}
    }

    public override void
    checkCert(string subjectDN, string issuerDN, Ice.Current current)
    {
	try
	{
	    IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con);
	    test(info.certs.Length == 2 &&
		 info.certs[0].Subject.Equals(subjectDN) &&
		 info.certs[0].Issuer.Equals(issuerDN));
	}
	catch(IceSSL.ConnectionInvalidException)
	{
	    test(false);
	}
    }

    public override void
    checkCipher(string cipher, Ice.Current current)
    {
	try
	{
	    IceSSL.ConnectionInfo info = IceSSL.Util.getConnectionInfo(current.con);
	    test(info.cipher.Equals(cipher));
	}
	catch(IceSSL.ConnectionInvalidException)
	{
	    test(false);
	}
    }

    internal void destroy()
    {
	communicator_.destroy();
    }

    private static void test(bool b)
    {
	if (!b)
	{
	    throw new Exception();
	}
    }

    private Ice.Communicator communicator_;
}

internal sealed class ServerFactoryI : ServerFactoryDisp_
{
    private static void test(bool b)
    {
	if (!b)
	{
	    throw new Exception();
	}
    }

    public override ServerPrx createServer(Properties props, Ice.Current current)
    {
    	Ice.InitializationData initData = new Ice.InitializationData();
	initData.properties = Ice.Util.createProperties();
	foreach(string key in props.Keys)
	{
	    initData.properties.setProperty(key, props[key]);
	}

	string[] args = new string[0];
	Ice.Communicator communicator = Ice.Util.initialize(ref args, initData);
	Ice.ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints("ServerAdapter", "ssl");
	ServerI server = new ServerI(communicator);
	Ice.ObjectPrx obj = adapter.addWithUUID(server);
	servers_[obj.ice_getIdentity()] = server;
	adapter.activate();

	return ServerPrxHelper.uncheckedCast(obj);
    }

    public override void destroyServer(ServerPrx srv, Ice.Current current)
    {
	Ice.Identity key = srv.ice_getIdentity();
	if(servers_.Contains(key))
	{
	    ServerI server = servers_[key] as ServerI;
	    server.destroy();
	    servers_.Remove(key);
	}
    }

    public override void shutdown(Ice.Current current)
    {
	test(servers_.Count == 0);
	current.adapter.getCommunicator().shutdown();
    }

    private Hashtable servers_ = new Hashtable();
}