File: admin_user.t

package info (click to toggle)
request-tracker5 5.0.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 80,216 kB
  • sloc: javascript: 191,898; perl: 87,146; sh: 1,412; makefile: 487; python: 37; php: 15
file content (182 lines) | stat: -rw-r--r-- 6,086 bytes parent folder | download | duplicates (4)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

use strict;
use warnings;

use RT::Test::Crypt
  GnuPG         => 1,
  tests         => undef,
  gnupg_options => {
    passphrase    => 'recipient',
    'trust-model' => 'always',
  };

RT::Test->import_gnupg_key( 'rt-test@example.com', 'secret' );

ok( my $user = RT::User->new( RT->SystemUser ) );
ok( $user->Load('root'), "loaded user 'root'" );
$user->SetEmailAddress('rt-test@example.com');

my ( $url, $m ) = RT::Test->started_ok;
ok( $m->login(), 'logged in' );

my $root = RT::User->new( $RT::SystemUser );
$root->Load('root');
ok( $root->id, 'loaded root' );


diag "test the history page" if $ENV{TEST_VERBOSE};
$m->get_ok( $url . '/Admin/Users/History.html?id=' . $root->id );
$m->content_contains('User created', 'has User created entry');

diag "test keys page" if $ENV{TEST_VERBOSE};
$m->follow_link_ok( { text => 'Keys' } );
$m->content_contains('Public key(s) for rt-test@example.com');
$m->content_contains('The key is ultimately trusted');
$m->content_contains('F0CB3B482CFA485680A4A0BDD328035D84881F1B');
$m->content_contains('Tue Aug 07 2007');
$m->content_contains('never');

$m->content_contains('GnuPG private key');

my $form = $m->form_with_fields('PrivateKey');
is( $form->find_input('PrivateKey')->value,
    '__empty_value__', 'default no private key' );
$m->submit_form_ok(
    {
        fields => { PrivateKey => 'F0CB3B482CFA485680A4A0BDD328035D84881F1B' },
        button => 'Update',
    },
    'submit PrivateKey form'
);

$m->content_contains('Set private key');
$form = $m->form_with_fields('PrivateKey');
is( $form->find_input('PrivateKey')->value,
    'F0CB3B482CFA485680A4A0BDD328035D84881F1B', 'set private key' );
$m->submit_form_ok(
    {
        fields => { PrivateKey => '__empty_value__' },
        button => 'Update',
    },
    'submit PrivateKey form'
);

$m->content_contains('Unset private key');
is( $form->find_input('PrivateKey')->value,
    '__empty_value__', 'unset private key' );
$form = $m->form_with_fields('PrivateKey');
$m->submit_form_ok(
    {
        fields => { PrivateKey => 'C798591AA831DBFB' },
        button => 'Update',
    },
    'submit PrivateKey form'
);
$m->text_contains(q{Invalid key C798591AA831DBFB for address 'rt-test@example.com'});


diag "Test user searches";

my @cf_names = qw( CF1 CF2 CF3 );
my @cfs = ();
foreach my $cf_name ( @cf_names ) {
    my $cf = RT::CustomField->new( RT->SystemUser );
    my ( $id, $msg ) = $cf->Create(
        Name => $cf_name,
        TypeComposite => 'Freeform-1',
        LookupType => RT::User->CustomFieldLookupType,
    );
    ok( $id, $msg );
    # Create a global ObjectCustomField record
    my $object = $cf->RecordClassFromLookupType->new( RT->SystemUser );
    ( $id, $msg ) = $cf->AddToObject( $object );
    ok( $id, $msg );
    push ( @cfs, $cf );
}
my $cf_1 = $cfs[0];
my $cf_2 = $cfs[1];
my $cf_3 = $cfs[2];

my @user_names = qw( user1 user2 user3 user4 );
my @users = ();
foreach my $user_name ( @user_names ) {
    my $user = RT::Test->load_or_create_user(
        Name => $user_name, Password => 'password',
    );
    ok( $user && $user->id, 'Created '.$user->Name.' with id '.$user->Id );
    push ( @users, $user );
}

$users[0]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );

$users[1]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
$users[1]->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );

$users[2]->AddCustomFieldValue( Field => $cf_1->id, Value => 'one' );
$users[2]->AddCustomFieldValue( Field => $cf_2->id, Value => 'two' );
$users[2]->AddCustomFieldValue( Field => $cf_3->id, Value => 'three' );

$m->get_ok( $url . '/Admin/Users/index.html' );
ok( $m->form_name( 'UsersAdmin' ), 'found the filter admin users form');
$m->select( UserField => 'Name', UserOp => 'LIKE' );
$m->field( UserString => 'user' );
$m->select( UserField2 => 'CustomField: '.$cf_1->Name, UserOp2 => 'LIKE' );
$m->field( UserString2 => 'one' );
$m->select( UserField3 => 'CustomField: '.$cf_2->Name, UserOp3 => 'LIKE' );
$m->field( UserString3 => 'two' );
$m->click( 'Go' );

diag "Verify results contain users 2 & 3, but not 1 & 4";
$m->content_contains( $users[1]->Name );
$m->content_contains( $users[2]->Name );
$m->content_lacks( $users[0]->Name );
$m->content_lacks( $users[3]->Name );

diag 'Test NULL value searches';
$m->form_name( 'UsersAdmin' );
$m->select( UserField2 => 'CustomField: '.$cf_2->Name, UserOp2 => 'is' );
$m->field( UserString2 => 'NULL' );
$m->field( UserString3 => '' );
$m->click( 'Go' );
$m->text_lacks( $_->Name ) for @users[1..2];
$m->text_contains( $_->Name ) for @users[0,3];

ok( $users[0]->SetRealName('user1') );
$m->form_name( 'UsersAdmin' );
$m->select( UserField2 => 'Real Name', UserOp2 => 'is' );
$m->field( UserString2 => 'NULL' );
$m->click( 'Go' );
$m->text_lacks( $_->Name ) for $users[0];
$m->text_contains( $_->Name ) for @users[1..3];

ok( $users[3]->SetPrivileged(0) );
$m->get_ok( $url . '/Admin/Users/index.html' );
$m->form_name('UsersAdmin');
$m->click('Go');
$m->text_contains( $_->Name, 'Found privileged users' ) for @users[ 0 .. 2 ];
$m->text_lacks( 'user4', 'No unprivileged users' );

# Nobody/RT_System is so common that could appear in the page, here we test
# links instead
ok( !$m->find_link( text => 'Nobody' ), 'No user Nobody' );
ok( !$m->find_link( text => 'RT_System' ), 'No user RT_System' );

$m->form_name('UsersAdmin');
$m->field( IncludeSystemGroups => 'Unprivileged' );
$m->click('Go');
$m->text_lacks( $_->Name, 'No privileged users' ) for @users[ 0 .. 2 ];
$m->text_contains( 'user4', 'Found unprivileged users' );
ok( !$m->find_link( text => 'Nobody' ), 'No user Nobody' );
ok( !$m->find_link( text => 'RT_System' ), 'No user RT_System' );

$m->form_name('UsersAdmin');
$m->field( IncludeSystemGroups => 'All' );
$m->click('Go');
$m->text_contains( $_->Name, 'Found privileged users' ) for @users[ 0 .. 2 ];
$m->text_contains( 'user4', 'Found unprivileged users' );
ok( !$m->find_link( text => 'Nobody' ), 'No user Nobody' );
ok( !$m->find_link( text => 'RT_System' ), 'No user RT_System' );

# TODO more /Admin/Users tests

done_testing;