-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtest_ldap_authentication.py
More file actions
1316 lines (1085 loc) · 49.6 KB
/
Copy pathtest_ldap_authentication.py
File metadata and controls
1316 lines (1085 loc) · 49.6 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Test class for Active Directory Feature
:Requirement: Ldapauthsource
:CaseAutomation: Automated
:CaseComponent: Authentication
:Team: Endeavour
:CaseImportance: High
"""
from fauxfactory import gen_url
from navmazing import NavigationTriesExceeded
import pyotp
import pytest
from robottelo.config import settings
from robottelo.constants import ANY_CONTEXT, LDAP_ATTR, PERMISSIONS
from robottelo.utils.datafactory import gen_string
from robottelo.utils.ldap import get_ldap_cacert_pem
pytestmark = [pytest.mark.run_in_one_thread]
EXTERNAL_GROUP_NAME = 'foobargroup'
@pytest.fixture
def ldap_usergroup_name(target_sat):
"""Return some random usergroup name,
and attempt to delete such usergroup when test finishes.
"""
usergroup_name = gen_string('alphanumeric')
yield usergroup_name
user_groups = target_sat.api.UserGroup().search(query={'search': f'name="{usergroup_name}"'})
if user_groups:
user_groups[0].delete()
@pytest.fixture
def ldap_tear_down(target_sat):
"""Teardown the all ldap settings user, usergroup and ldap delete"""
yield
ldap_auth_sources = target_sat.api.AuthSourceLDAP().search()
for ldap_auth in ldap_auth_sources:
users = target_sat.api.User(auth_source=ldap_auth).search()
for user in users:
user.delete()
ldap_auth.delete()
@pytest.fixture
def external_user_count(target_sat):
"""return the external auth source user count"""
users = target_sat.api.User().search()
return len([user for user in users if user.auth_source_name == 'External'])
@pytest.fixture
def groups_teardown(target_sat):
"""teardown for groups created for external/remote groups"""
yield
# teardown groups
for group_name in ('sat_users', 'sat_admins', EXTERNAL_GROUP_NAME):
user_groups = target_sat.api.UserGroup().search(query={'search': f'name="{group_name}"'})
if user_groups:
user_groups[0].delete()
@pytest.fixture
def rhsso_groups_teardown(default_sso_host):
"""Teardown the rhsso groups"""
yield
for group_name in ('sat_users', 'sat_admins'):
default_sso_host.delete_rhsso_group(group_name)
@pytest.fixture
def ipa_add_user(default_ipa_host):
"""Create an IPA user and delete it"""
test_user = gen_string('alpha')
default_ipa_host.create_user(test_user)
yield test_user
default_ipa_host.delete_user(test_user)
def generate_otp(secret):
"""Return the time_based_otp"""
time_otp = pyotp.TOTP(secret)
return time_otp.now()
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True)
def test_positive_end_to_end(session, ldap_auth_source, ldap_tear_down):
"""Perform end to end testing for LDAP authentication component
:id: a6528239-e090-4379-a850-3900ee625b24
:expectedresults: All expected CRUD actions finished successfully
:CaseImportance: High
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
new_server = gen_url()
ldap_auth_name = gen_string('alphanumeric')
with session:
session.ldapauthentication.create(
{
'ldap_server.name': ldap_auth_name,
'ldap_server.host': ldap_data['ldap_hostname'],
'ldap_server.server_type': ldap_data['server_type'],
'account.account_name': ldap_data['ldap_user_name'],
'account.password': ldap_data['ldap_user_passwd'],
'account.base_dn': ldap_data['base_dn'],
'account.groups_base_dn': ldap_data['group_base_dn'],
'attribute_mappings.login': ldap_data['attr_login'],
'attribute_mappings.first_name': LDAP_ATTR['firstname'],
'attribute_mappings.last_name': LDAP_ATTR['surname'],
'attribute_mappings.mail': LDAP_ATTR['mail'],
}
)
assert session.ldapauthentication.read_table_row(ldap_auth_name)['Name'] == ldap_auth_name
session.ldapauthentication.update(ldap_auth_name, {'ldap_server.host': new_server})
assert session.ldapauthentication.read_table_row(ldap_auth_name)['Server'] == new_server
session.ldapauthentication.delete(ldap_auth_name)
assert not session.ldapauthentication.read_table_row(ldap_auth_name)
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True)
@pytest.mark.upgrade
def test_positive_create_org_and_loc(session, ldap_auth_source, ldap_tear_down, target_sat):
"""Create LDAP auth_source with org and loc assigned.
:id: 4f595af4-fc01-44c6-a614-a9ec827e3c3c
:steps:
1. Create a new LDAP Auth source, provide organization and
location information.
2. Fill in all the fields appropriately.
:expectedresults: Whether creating LDAP Auth and associating org
and loc is successful.
:CaseImportance: Medium
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
org = target_sat.api.Organization().create()
loc = target_sat.api.Location().create()
ldap_auth_name = gen_string('alphanumeric')
with session:
session.ldapauthentication.create(
{
'ldap_server.name': ldap_auth_name,
'ldap_server.host': ldap_data['ldap_hostname'],
'ldap_server.server_type': ldap_data['server_type'],
'account.account_name': ldap_data['ldap_user_name'],
'account.password': ldap_data['ldap_user_passwd'],
'account.base_dn': ldap_data['base_dn'],
'account.groups_base_dn': ldap_data['group_base_dn'],
'attribute_mappings.login': ldap_data['attr_login'],
'attribute_mappings.first_name': LDAP_ATTR['firstname'],
'attribute_mappings.last_name': LDAP_ATTR['surname'],
'attribute_mappings.mail': LDAP_ATTR['mail'],
'locations.resources.assigned': [loc.name],
'organizations.resources.assigned': [org.name],
}
)
session.organization.select(org_name=org.name)
session.location.select(loc_name=loc.name)
assert session.ldapauthentication.read_table_row(ldap_auth_name)['Name'] == ldap_auth_name
ldap_source = session.ldapauthentication.read(ldap_auth_name)
assert ldap_source['ldap_server']['name'] == ldap_auth_name
assert ldap_source['ldap_server']['host'] == ldap_data['ldap_hostname']
assert ldap_source['ldap_server']['port'] == '389'
assert ldap_source['ldap_server']['server_type'] == ldap_data['server_type']
assert ldap_source['account']['account_name'] == ldap_data['ldap_user_name']
assert ldap_source['account']['base_dn'] == ldap_data['base_dn']
assert ldap_source['account']['groups_base_dn'] == ldap_data['group_base_dn']
assert not ldap_source['account']['onthefly_register']
assert ldap_source['account']['usergroup_sync']
assert ldap_source['attribute_mappings']['login'] == ldap_data['attr_login']
assert ldap_source['attribute_mappings']['first_name'] == LDAP_ATTR['firstname']
assert ldap_source['attribute_mappings']['last_name'] == LDAP_ATTR['surname']
assert ldap_source['attribute_mappings']['mail'] == LDAP_ATTR['mail']
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True)
def test_positive_add_katello_role(
test_name, session, ldap_usergroup_name, ldap_auth_source, ldap_tear_down, target_sat
):
"""Associate katello roles to User Group.
[belonging to external User Group.]
:id: aa5e3bf4-cb42-43a4-93ea-a2eea54b847a
:steps:
1. Create an UserGroup.
2. Assign some foreman roles to UserGroup.
3. Create and associate an External UserGroup.
:expectedresults: Whether a User belonging to User Group is able to
access katello entities as per roles.
:CaseImportance: Medium
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
auth_source_name = f'LDAP-{auth_source.name}'
ak_name = gen_string('alpha')
user_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']}
katello_role = target_sat.api.Role().create()
target_sat.api_factory.create_role_permissions(katello_role, user_permissions)
with session:
session.usergroup.create(
{
'usergroup.name': ldap_usergroup_name,
'roles.resources.assigned': [katello_role.name],
'external_groups.name': EXTERNAL_GROUP_NAME,
'external_groups.auth_source': auth_source_name,
}
)
assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name
session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME)
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as session:
with pytest.raises(NavigationTriesExceeded):
session.architecture.search('')
session.activationkey.create({'name': ak_name})
assert session.activationkey.search(ak_name)[0]['Name'] == ak_name
current_user = session.activationkey.read(ak_name, 'current_user')['current_user']
assert ldap_data['ldap_user_shown_name'] in current_user
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True)
@pytest.mark.upgrade
def test_positive_update_external_roles(
test_name, session, ldap_usergroup_name, ldap_auth_source, ldap_tear_down, target_sat
):
"""Added AD UserGroup roles get pushed down to user
:id: f3ca1aae-5461-4af3-a508-82679bb6afed
:setup: assign additional roles to the UserGroup
:steps:
1. Create an UserGroup.
2. Assign some roles to UserGroup.
3. Create an External AD UserGroup as per the UserGroup name in AD.
4. Login to sat6 with the AD user.
5. Assign additional roles to the UserGroup.
6. Login to sat6 with LDAP user that is part of aforementioned
UserGroup.
:expectedresults: User has access to all NEW functional areas that are
assigned to aforementioned UserGroup.
:BlockedBy: SAT-42705
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
ak_name = gen_string('alpha')
auth_source_name = f'LDAP-{auth_source.name}'
location_name = gen_string('alpha')
foreman_role = target_sat.api.Role().create()
katello_role = target_sat.api.Role().create()
foreman_permissions = {'Location': PERMISSIONS['Location']}
katello_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']}
target_sat.api_factory.create_role_permissions(foreman_role, foreman_permissions)
target_sat.api_factory.create_role_permissions(katello_role, katello_permissions)
with session:
session.usergroup.create(
{
'usergroup.name': ldap_usergroup_name,
'roles.resources.assigned': [foreman_role.name],
'external_groups.name': EXTERNAL_GROUP_NAME,
'external_groups.auth_source': auth_source_name,
}
)
assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
with pytest.raises(NavigationTriesExceeded):
ldapsession.architecture.search('')
ldapsession.location.create({'name': location_name})
location = target_sat.api.Location().search(
query={'search': f'name="{location_name}"'}
)[0]
assert location.name == location_name
session.usergroup.update(
ldap_usergroup_name, {'roles.resources.assigned': [katello_role.name]}
)
session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME)
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as session:
session.activationkey.create({'name': ak_name})
assert session.activationkey.search(ak_name)[0]['Name'] == ak_name
current_user = session.activationkey.read(ak_name, 'current_user')['current_user']
assert ldap_data['ldap_user_shown_name'] == current_user
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True)
@pytest.mark.upgrade
def test_positive_delete_external_roles(
test_name, session, ldap_usergroup_name, ldap_tear_down, ldap_auth_source, target_sat
):
"""Deleted AD UserGroup roles get pushed down to user
:id: 479bc8fe-f6a3-4c89-8c7e-3d997315383f
:setup: delete roles from an AD UserGroup
:CaseImportance: Medium
:BlockedBy: SAT-42705
:steps:
1. Create an UserGroup.
2. Assign some roles to UserGroup.
3. Create an External AD UserGroup as per the UserGroup name in AD.
4. Login to sat6 with the AD user.
5. Unassign some of the existing roles of the UserGroup.
6. Login to sat6 with LDAP user that is part of aforementioned
UserGroup.
:expectedresults: User no longer has access to all deleted functional
areas that were assigned to aforementioned UserGroup.
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
auth_source_name = f'LDAP-{auth_source.name}'
location_name = gen_string('alpha')
foreman_role = target_sat.api.Role().create()
foreman_permissions = {'Location': PERMISSIONS['Location']}
target_sat.api_factory.create_role_permissions(foreman_role, foreman_permissions)
with session:
session.usergroup.create(
{
'usergroup.name': ldap_usergroup_name,
'roles.resources.assigned': [foreman_role.name],
'external_groups.name': EXTERNAL_GROUP_NAME,
'external_groups.auth_source': auth_source_name,
}
)
assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
with pytest.raises(NavigationTriesExceeded):
ldapsession.architecture.search('')
ldapsession.location.create({'name': location_name})
location = target_sat.api.Location().search(
query={'search': f'name="{location_name}"'}
)[0]
assert location.name == location_name
session.usergroup.update(
ldap_usergroup_name, {'roles.resources.unassigned': [foreman_role.name]}
)
with (
target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession,
pytest.raises(NavigationTriesExceeded),
):
ldapsession.location.create({'name': gen_string('alpha')})
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True)
def test_positive_update_external_user_roles(
test_name, session, ldap_usergroup_name, ldap_tear_down, ldap_auth_source, target_sat
):
"""Assure that user has roles/can access feature areas for
additional roles assigned outside any roles assigned by his group
:id: a487f7d6-22f2-4e42-b34f-8d984f721c83
:setup: Assign roles to UserGroup and configure external UserGroup
subsequently assign specified roles to the user(s). roles that are
not part of the larger UserGroup
:steps:
1. Create an UserGroup.
2. Assign some roles to UserGroup.
3. Create an External AuthSource UserGroup as per the UserGroup name
in AuthSource(e.g. AD/IDM)
4. Assign some more roles to a User(which is part of external Auth Source.
UserGroup) at the User level.
5. Login to Satellite with the above AuthSource user and attempt to access areas
assigned specifically to user.
:expectedresults: User can access not only those feature areas in his
UserGroup but those additional feature areas / roles assigned
specifically to user
:CaseImportance: Medium
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
ak_name = gen_string('alpha')
auth_source_name = f'LDAP-{auth_source.name}'
location_name = gen_string('alpha')
foreman_role = target_sat.api.Role().create()
katello_role = target_sat.api.Role().create()
foreman_permissions = {'Location': PERMISSIONS['Location']}
katello_permissions = {'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey']}
target_sat.api_factory.create_role_permissions(foreman_role, foreman_permissions)
target_sat.api_factory.create_role_permissions(katello_role, katello_permissions)
with session:
session.usergroup.create(
{
'usergroup.name': ldap_usergroup_name,
'roles.resources.assigned': [foreman_role.name],
'external_groups.name': EXTERNAL_GROUP_NAME,
'external_groups.auth_source': auth_source_name,
}
)
assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
ldapsession.location.create({'name': location_name})
location = target_sat.api.Location().search(
query={'search': f'name="{location_name}"'}
)[0]
assert location.name == location_name
session.location.select(ANY_CONTEXT['location'])
session.user.update(
ldap_data['ldap_user_name'], {'roles.resources.assigned': [katello_role.name]}
)
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
with pytest.raises(NavigationTriesExceeded):
ldapsession.architecture.search('')
ldapsession.activationkey.create({'name': ak_name})
assert ldapsession.activationkey.search(ak_name)[0]['Name'] == ak_name
current_user = ldapsession.activationkey.read(ak_name, 'current_user')['current_user']
assert ldap_data['ldap_user_shown_name'] == current_user
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True)
def test_positive_add_admin_role_with_org_loc(
test_name,
session,
ldap_usergroup_name,
module_org,
ldap_tear_down,
ldap_auth_source,
target_sat,
):
"""Associate Admin role to User Group with org and loc set.
[belonging to external User Group.]
:id: 00841778-f89e-4445-a6c6-f1470b6da32e
:parametrized: yes
:BlockedBy: SAT-42705
:setup: LDAP Auth Source should be created with Org and Location
Associated.
:steps:
1. Create an UserGroup.
2. Assign admin role to UserGroup.
3. Create and associate an External UserGroup.
:CaseImportance: Medium
:expectedresults: Whether a User belonging to User Group is able to
access some of the pages, with the associated org and loc
in LDAP Auth source page as the context set.
"""
ldap_data, auth_source = ldap_auth_source
auth_source_name = f'LDAP-{auth_source.name}'
ak_name = gen_string('alpha')
location_name = gen_string('alpha')
with session:
session.usergroup.create(
{
'usergroup.name': ldap_usergroup_name,
'roles.admin': True,
'external_groups.name': EXTERNAL_GROUP_NAME,
'external_groups.auth_source': auth_source_name,
}
)
assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as session:
session.location.create({'name': location_name})
assert session.location.search(location_name)[0]['Name'] == location_name
location = session.location.read(location_name, ['current_user', 'primary'])
assert ldap_data['ldap_user_shown_name'] in location['current_user']
assert location['primary']['name'] == location_name
session.organization.select(module_org.name)
session.activationkey.create({'name': ak_name})
assert session.activationkey.search(ak_name)[0]['Name'] == ak_name
ak = session.activationkey.read(ak_name, 'details.name')
assert ak['details']['name'] == ak_name
@pytest.mark.parametrize('ldap_auth_source', ['AD_2019', 'IPA'], indirect=True)
def test_positive_add_foreman_role_with_org_loc(
test_name,
session,
ldap_usergroup_name,
module_org,
module_location,
ldap_tear_down,
ldap_auth_source,
module_target_sat,
):
"""Associate foreman roles to User Group with org and loc set.
[belonging to external User Group.]
:id: b39d7b2a-6d78-4c35-969a-37c8317ce64f
:parametrized: yes
:setup: LDAP Auth Source should be created with Org and Location
Associated.
:steps:
1. Create an UserGroup.
2. Assign some foreman roles to UserGroup.
3. Create and associate an External UserGroup.
:CaseImportance: Medium
:expectedresults: Whether a User belonging to User Group is able to
access foreman entities as per roles, with the associated org and
loc in LDAP Auth source page as the context set.
"""
ldap_data, auth_source = ldap_auth_source
auth_source_name = f'LDAP-{auth_source.name}'
name = gen_string('alpha')
user_permissions = {
'Hostgroup': PERMISSIONS['Hostgroup'],
'Location': ['assign_locations'],
'Organization': ['assign_organizations'],
}
foreman_role = module_target_sat.api.Role().create()
module_target_sat.api_factory.create_role_permissions(foreman_role, user_permissions)
with session:
session.usergroup.create(
{
'usergroup.name': ldap_usergroup_name,
'roles.resources.assigned': [foreman_role.name],
'external_groups.name': EXTERNAL_GROUP_NAME,
'external_groups.auth_source': auth_source_name,
}
)
assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name
session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME)
with module_target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
with pytest.raises(NavigationTriesExceeded):
ldapsession.architecture.search('')
ldapsession.hostgroup.create({'host_group.name': name})
hostgroup = session.hostgroup.read(name, ['organizations', 'locations'])
assert len(hostgroup['organizations']['resources']['assigned']) == 1
assert module_org.name in hostgroup['organizations']['resources']['assigned']
assert len(hostgroup['locations']['resources']['assigned']) == 1
assert module_location.name in hostgroup['locations']['resources']['assigned']
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True)
def test_positive_add_katello_role_with_org(
test_name,
session,
ldap_usergroup_name,
module_org,
ldap_tear_down,
ldap_auth_source,
target_sat,
):
"""Associate katello roles to User Group with org set.
[belonging to external User Group.]
:id: a2ebd4de-eb0a-47da-81e8-00942eedcbf6
:parametrized: yes
:setup: LDAP Auth Source should be created with Organization associated.
:steps:
1. Create an UserGroup.
2. Assign some katello roles to UserGroup.
3. Create and associate an External UserGroup.
:CaseImportance: Medium
:expectedresults: Whether a User belonging to User Group is able to
access katello entities as per roles, with the associated org
in LDAP Auth source page as the context set.
"""
ldap_data, auth_source = ldap_auth_source
auth_source_name = f'LDAP-{auth_source.name}'
ak_name = gen_string('alpha')
user_permissions = {
'Katello::ActivationKey': PERMISSIONS['Katello::ActivationKey'],
'Location': ['assign_locations'],
'Organization': ['assign_organizations'],
}
katello_role = target_sat.api.Role().create()
target_sat.api_factory.create_role_permissions(katello_role, user_permissions)
different_org = target_sat.api.Organization().create()
with session:
session.usergroup.create(
{
'usergroup.name': ldap_usergroup_name,
'roles.resources.assigned': [katello_role.name],
'external_groups.name': EXTERNAL_GROUP_NAME,
'external_groups.auth_source': auth_source_name,
}
)
assert session.usergroup.search(ldap_usergroup_name)[0]['Name'] == ldap_usergroup_name
session.usergroup.refresh_external_group(ldap_usergroup_name, EXTERNAL_GROUP_NAME)
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
with pytest.raises(NavigationTriesExceeded):
ldapsession.architecture.search('')
ldapsession.activationkey.create({'name': ak_name})
results = session.activationkey.search(ak_name)
assert results[0]['Name'] == ak_name
session.organization.select(different_org.name)
assert session.activationkey.search(ak_name)[0]['Name'] != ak_name
ak = (
target_sat.api.ActivationKey(organization=module_org)
.search(query={'search': f'name={ak_name}'})[0]
.read()
)
assert ak.organization.id == module_org.id
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True)
@pytest.mark.upgrade
def test_positive_create_user_in_ldap_mode(session, ldap_auth_source, ldap_tear_down):
"""Create User in ldap mode
:id: 0668b2ca-831e-4568-94fb-80e45dd7d001
:parametrized: yes
:CaseImportance: Medium
:expectedresults: User is created without specifying the password
"""
ldap_data, auth_source = ldap_auth_source
auth_source_name = f'LDAP-{auth_source.name}'
name = gen_string('alpha')
with session:
session.user.create({'user.login': name, 'user.auth': auth_source_name})
assert session.user.search(name)[0]['Username'] == name
user_values = session.user.read(name)
assert user_values['user']['auth'] == auth_source_name
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True)
def test_positive_login_user_no_roles(test_name, ldap_tear_down, ldap_auth_source, target_sat):
"""Login with LDAP Auth for user with no roles/rights
:id: 7dc8d9a7-ff08-4d8e-a842-d370ffd69741
:setup: assure properly functioning server for authentication
:steps: Login to server with an user.
:expectedresults: Log in to foreman UI successfully but cannot access
functional areas of UI
:CaseImportance: Medium
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
ldapsession.task.read_all()
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA'], indirect=True)
@pytest.mark.upgrade
def test_positive_login_user_basic_roles(
test_name, session, ldap_tear_down, ldap_auth_source, target_sat
):
"""Login with LDAP for user with roles/rights
:id: ef202e94-8e5d-4333-a4bc-e573b03ebfc8
:parametrized: yes
:setup: assure properly functioning server for authentication
:steps: Login to server with an user.
:expectedresults: Log in to foreman UI successfully and can access
appropriate functional areas in UI
"""
ldap_data, auth_source = ldap_auth_source
name = gen_string('alpha')
role = target_sat.api.Role().create()
permissions = {'Architecture': PERMISSIONS['Architecture']}
target_sat.api_factory.create_role_permissions(role, permissions)
with (
target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession,
pytest.raises(NavigationTriesExceeded),
):
ldapsession.usergroup.search('')
with session:
session.user.update(ldap_data['ldap_user_name'], {'roles.resources.assigned': [role.name]})
with target_sat.ui_session(
test_name, ldap_data['ldap_user_name'], ldap_data['ldap_user_passwd']
) as ldapsession:
ldapsession.architecture.create({'name': name})
assert ldapsession.architecture.search(name)[0]['Name'] == name
@pytest.mark.upgrade
def test_positive_login_user_password_otp(
auth_source_ipa, default_ipa_host, test_name, ldap_tear_down, target_sat
):
"""Login with password with time based OTP
:id: be7eb5d6-3228-4660-aa64-c56f9f3ec5e0
:setup: Assure properly functioning IPA server for authentication
:steps: Login to server with an IPA user with time_based OTP.
:expectedresults: Log in to foreman UI successfully
:CaseImportance: Medium
"""
otp_pass = (
f"{default_ipa_host.ldap_user_passwd}{generate_otp(default_ipa_host.time_based_secret)}"
)
with (
target_sat.ui_session(
test_name, default_ipa_host.ipa_otp_username, otp_pass
) as ldapsession,
pytest.raises(NavigationTriesExceeded),
):
ldapsession.user.search('')
users = target_sat.api.User().search(
query={'search': f'login="{default_ipa_host.ipa_otp_username}"'}
)
assert users[0].login == default_ipa_host.ipa_otp_username
def test_negative_login_user_with_invalid_password_otp(
auth_source_ipa, default_ipa_host, test_name, ldap_tear_down, target_sat
):
"""Login with password with time based OTP
:id: 3718c86e-5976-4fb8-9c80-4685d53bd955
:setup: Assure properly functioning IPA server for authentication
:steps: Login to server with an IPA user with invalid OTP.
:expectedresults: Log in to foreman UI should be failed
:CaseImportance: Medium
"""
password_with_otp = (
f"{default_ipa_host.ldap_user_passwd}{gen_string(str_type='numeric', length=6)}"
)
with target_sat.ui_session(
test_name, default_ipa_host.ipa_otp_username, password_with_otp
) as ldapsession:
with pytest.raises(NavigationTriesExceeded) as error:
ldapsession.user.search('')
assert error.typename == 'NavigationTriesExceeded'
@pytest.mark.parametrize("ldap_auth_source", ["AD", "IPA", "OPENLDAP"], indirect=True)
def test_positive_test_connection_functionality(session, ldap_auth_source):
"""Verify for a positive test connection response
:id: 5daf3976-9b5c-11ea-96f8-4ceb42ab8dbc
:steps: Assert test connection of AD, IPA and OPENLDAP.
:expectedresults: Positive test connection of AD and IPA
:CaseImportance: Medium
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
with session:
session.ldapauthentication.test_connection({'ldap_server.host': ldap_data['ldap_hostname']})
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True)
def test_negative_login_with_incorrect_password(test_name, ldap_auth_source, target_sat):
"""Attempt to login in Satellite an user with the wrong password
:id: 3f09de90-a656-11ea-aa43-4ceb42ab8dbc
:steps:
1. Randomly generate a string as a incorrect password.
2. Try login with the incorrect password
:expectedresults: Login fails
:CaseImportance: Medium
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
incorrect_password = gen_string('alphanumeric')
with target_sat.ui_session(
test_name, user=ldap_data['ldap_user_name'], password=incorrect_password
) as ldapsession:
with pytest.raises(NavigationTriesExceeded) as error:
ldapsession.user.search('')
assert error.typename == 'NavigationTriesExceeded'
def test_negative_login_with_disable_user(
default_ipa_host, auth_source_ipa, ldap_tear_down, target_sat
):
"""Disabled IDM user cannot login
:id: 49f28006-aa1f-11ea-90d3-4ceb42ab8dbc
:steps: Try login from the disabled user
:CaseImportance: Medium
:expectedresults: Login fails
"""
with target_sat.ui_session(
user=default_ipa_host.disabled_user_ipa, password=default_ipa_host.ldap_user_passwd
) as ldapsession:
with pytest.raises(NavigationTriesExceeded) as error:
ldapsession.user.search('')
assert error.typename == 'NavigationTriesExceeded'
def test_email_of_the_user_should_be_copied(
session, default_ipa_host, auth_source_ipa, ldap_tear_down, target_sat
):
"""Email of the user created in idm server ( set as external authorization source )
should be copied to the satellite.
:id: 9ce7d7c6-dc73-11ea-8a97-4ceb42ab8dbc
:steps:
1. Create a new auth source with onthefly enabled
2. Login to the satellite with the user (from IDM) to create the account
3. Assert the email of the newly created user
:CaseImportance: Medium
:expectedresults: Email is copied to Satellite:
"""
result = default_ipa_host.find_user(default_ipa_host.ldap_user_name)
for line in result.strip().splitlines():
if 'Email' in line:
_, result = line.split(': ', 2)
break
with target_sat.ui_session(
user=default_ipa_host.ldap_user_name, password=default_ipa_host.ldap_user_passwd
) as ldapsession:
ldapsession.bookmark.search('controller = hosts')
with session:
user_value = session.user.read(default_ipa_host.ldap_user_name, widget_names='user')
assert user_value['user']['mail'] == result
def test_deleted_idm_user_should_not_be_able_to_login(
target_sat, default_ipa_host, auth_source_ipa, ldap_tear_down
):
"""After deleting a user in IDM, user should not be able to login into satellite
:id: 18ad0526-e083-11ea-b1ad-4ceb42ab8dbc
:steps:
1. Create a new auth source with onthefly enabled
2. Login to satellite to create the user
3. Delete the user from IDM
4. Try login to the satellite from the user
:expectedresults: User login fails
"""
test_user = gen_string('alpha')
default_ipa_host.create_user(test_user)
with target_sat.ui_session(user=test_user, password=settings.ipa.password) as ldapsession:
ldapsession.bookmark.search('controller = hosts')
default_ipa_host.delete_user(test_user)
with target_sat.ui_session(user=test_user, password=settings.ipa.password) as ldapsession:
with pytest.raises(NavigationTriesExceeded) as error:
ldapsession.user.search('')
assert error.typename == 'NavigationTriesExceeded'
@pytest.mark.parametrize('ldap_auth_source', ['AD', 'IPA', 'OPENLDAP'], indirect=True)
def test_onthefly_functionality(session, ldap_auth_source, ldap_tear_down, target_sat):
"""User will not be created automatically in Satellite if onthefly is
disabled
:id: 6998de30-ef77-11ea-a0ce-0c7a158cbff4
:steps:
1. Create an auth source with onthefly disabled
2. Try login with a user from auth source
:expectedresults: Login fails
:CaseImportance: Medium
:parametrized: yes
"""
ldap_data, auth_source = ldap_auth_source
ldap_auth_name = gen_string('alphanumeric')
with session:
session.ldapauthentication.create(
{
'ldap_server.name': ldap_auth_name,
'ldap_server.host': ldap_data['ldap_hostname'],
'ldap_server.server_type': ldap_data['server_type'],
'account.account_name': ldap_data['ldap_user_cn'],
'account.password': ldap_data['ldap_user_passwd'],
'account.base_dn': ldap_data['base_dn'],
'account.groups_base_dn': ldap_data['group_base_dn'],
'account.onthefly_register': False,
'attribute_mappings.login': ldap_data['attr_login'],
'attribute_mappings.first_name': LDAP_ATTR['firstname'],
'attribute_mappings.last_name': LDAP_ATTR['surname'],
'attribute_mappings.mail': LDAP_ATTR['mail'],
}
)
with target_sat.ui_session(
user=ldap_data['ldap_user_name'], password=ldap_data['ldap_user_passwd']
) as ldapsession:
with pytest.raises(NavigationTriesExceeded) as error:
ldapsession.user.search('')
assert error.typename == 'NavigationTriesExceeded'
@pytest.mark.stubbed
def test_login_logout_using_cac_card():
"""Verify Satellite Integration with RHSSO Server Login, Logout using CAC Card from Satellite UI
:id: e79385ac-f679-11ea-b961-d46d6dd3b5b2
:CaseImportance: High
:CaseAutomation: ManualOnly
:steps:
1. configure the Satellite with RH-SSO instance
2. configure the firefox to use the CAC card cert, insert the CAC card
3. open the satellite url from firefox browser, authenticate using CAC card
:expectedresults: Satellite login/logout should be successful
"""
@pytest.mark.stubbed
def test_timeout_and_cac_card_ejection():
"""Verify CAC card ejection and timeout with Satellite integrated with RHSSO
:id: 8de96d2a-f67c-11ea-8a63-d46d6dd3b5b2
:CaseImportance: High
:CaseAutomation: ManualOnly
:steps:
1. configure the Satellite with RH-SSO instance
2. configure the firefox to use the CAC card cert, insert the CAC card
3. open the satellite url from firefox browser, authenticate using CAC card
4. setup the timeout setting in satellite
5. eject the cac card