1# See the file LICENSE for redistribution information.
2#
3# Copyright (c) 1996,2008 Oracle.  All rights reserved.
4#
5# $Id: rpc004.tcl,v 12.7 2008/01/08 20:58:53 bostic Exp $
6#
7# TEST	rpc004
8# TEST	Test RPC server and security
9proc rpc004 { } {
10	global __debug_on
11	global __debug_print
12	global errorInfo
13	global passwd
14	global has_crypto
15	global rpc_svc
16	source ./include.tcl
17
18	puts "Rpc004: RPC server + security"
19	puts "Rpc004: Using $rpc_svc"
20	# Skip test if release does not support encryption.
21	if { $has_crypto == 0 } {
22		puts "Skipping test rpc004 for non-crypto release."
23		return
24	}
25
26	cleanup $testdir NULL
27	set dpid [rpc_server_start 1]
28	puts "\tRpc004.a: Started server, pid $dpid"
29
30	#
31	# Wrap the test in a catch statement so we can still kill
32	# the rpc server even if the test fails.
33	#
34	set status [catch {
35		tclsleep 2
36		remote_cleanup $rpc_server $rpc_testdir $testdir
37
38		puts "\tRpc004.b: Creating environment"
39
40		set testfile "rpc004.db"
41		set testfile1 "rpc004a.db"
42		set home [file tail $rpc_testdir]
43
44		set env [eval {berkdb_env -create -mode 0644 -home $home \
45		    -server $rpc_server -encryptaes $passwd -txn}]
46		error_check_good lock_env:open [is_valid_env $env] TRUE
47
48		puts "\tRpc004.c: Opening a non-encrypted database"
49		#
50		# NOTE: the type of database doesn't matter, just use btree.
51		set db [eval {berkdb_open -auto_commit -create -btree \
52		    -mode 0644} -env $env $testfile]
53		error_check_good dbopen [is_valid_db $db] TRUE
54
55		puts "\tRpc004.d: Opening an encrypted database"
56		set db1 [eval {berkdb_open -auto_commit -create -btree \
57		    -mode 0644} -env $env -encrypt $testfile1]
58		error_check_good dbopen [is_valid_db $db1] TRUE
59
60		set txn [$env txn]
61		error_check_good txn [is_valid_txn $txn $env] TRUE
62		puts "\tRpc004.e: Put/get on both databases"
63		set key "key"
64		set data "data"
65
66		set ret [$db put -txn $txn $key $data]
67		error_check_good db_put $ret 0
68		set ret [$db get -txn $txn $key]
69		error_check_good db_get $ret [list [list $key $data]]
70		set ret [$db1 put -txn $txn $key $data]
71		error_check_good db1_put $ret 0
72		set ret [$db1 get -txn $txn $key]
73		error_check_good db1_get $ret [list [list $key $data]]
74
75		error_check_good txn_commit [$txn commit] 0
76		error_check_good db_close [$db close] 0
77		error_check_good db1_close [$db1 close] 0
78		error_check_good env_close [$env close] 0
79
80		# Cleanup our environment because it's encrypted
81		remote_cleanup $rpc_server $rpc_testdir $testdir
82	} res]
83	if { $status != 0 } {
84		puts $res
85	}
86	tclkill $dpid
87}
88