"Fossies" - the Fresh Open Source Software Archive 
Member "apache-zookeeper-3.8.1/zookeeper-contrib/zookeeper-contrib-zkperl/t/70_sasl.t" (25 Jan 2023, 3396 Bytes) of package /linux/misc/apache-zookeeper-3.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested text file into HTML format (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 # Net::ZooKeeper - Perl extension for Apache ZooKeeper
2 #
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18
19 use File::Spec;
20 use Test::More tests => 7;
21 use JSON::PP qw(decode_json);
22
23 BEGIN { use_ok('Net::ZooKeeper', qw(:all)) };
24
25
26 my $test_dir;
27 (undef, $test_dir, undef) = File::Spec->splitpath($0);
28 require File::Spec->catfile($test_dir, 'util.pl');
29
30 my($hosts, $root_path, $node_path) = zk_test_setup(0);
31
32 my $sasl_options = $ENV{'ZK_TEST_SASL_OPTIONS'};
33 if (defined($sasl_options)) {
34 $sasl_options = decode_json($sasl_options);
35 }
36
37 SKIP: {
38 skip 'no sasl_options', 6 unless defined($sasl_options);
39
40 my $zkh = Net::ZooKeeper->new($hosts,
41 'sasl_options' => $sasl_options);
42
43 my $path = $zkh->create($node_path, 'foo',
44 'acl' => ZOO_OPEN_ACL_UNSAFE) if (defined($zkh));
45
46 skip 'no connection to ZooKeeper', 36 unless
47 (defined($path) and $path eq $node_path);
48
49 ## _zk_acl_constant()
50
51 my $acl_node_path = "$node_path/a1";
52
53 my $sasl_acl = [
54 {
55 'perms' => ZOO_PERM_READ,
56 'scheme' => 'world',
57 'id' => 'anyone'
58 },
59 {
60 'perms' => ZOO_PERM_ALL,
61 'scheme' => 'sasl',
62 'id' => $sasl_options->{user}
63 }
64 ];
65
66 $path = $zkh->create($acl_node_path, 'foo', 'acl' => $sasl_acl);
67 is($path, $acl_node_path,
68 'create(): created node with SASL ACL');
69
70
71 ## get_acl()
72
73 @acl = ('abc');
74 @acl = $zkh->get_acl($acl_node_path);
75 is_deeply(\@acl, $sasl_acl,
76 'get_acl(): retrieved SASL ACL');
77
78 SKIP: {
79 my $zkh2 = Net::ZooKeeper->new($hosts);
80
81 my $ret = $zkh->exists($root_path) if (defined($zkh));
82
83 skip 'no connection to ZooKeeper', 1 unless
84 (defined($ret) and $ret);
85
86 my $node = $zkh2->get($acl_node_path);
87 is($node, 'foo',
88 'get(): retrieved node value with world ACL');
89
90 $ret = $zkh2->set($acl_node_path, 'bar');
91 ok((!$ret and $zkh2->get_error() == ZNOAUTH and $! eq ''),
92 'set(): node value unchanged if no auth');
93 }
94
95 my $ret = $zkh->set($acl_node_path, 'bar');
96 ok($ret,
97 'set(): set node with SASL ACL');
98
99 my $node = $zkh->get($acl_node_path);
100 is($node, 'bar',
101 'get(): retrieved new node value with SASL ACL');
102
103 $ret = $zkh->delete($acl_node_path);
104 diag(sprintf('unable to delete node %s: %d, %s',
105 $acl_node_path, $zkh->get_error(), $!)) unless ($ret);
106
107 $ret = $zkh->delete($node_path);
108 diag(sprintf('unable to delete node %s: %d, %s',
109 $node_path, $zkh->get_error(), $!)) unless ($ret);
110 }