summaryrefslogtreecommitdiffstats
path: root/test/functional_auth/gswauth/test_gswauth_cli.py
blob: d47e062cf10d558c682af62c6e0fa34a2d8cfac7 (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
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
#!/usr/bin/python

# Copyright (c) 2010-2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from nose import SkipTest
import commands
import os
from test import get_config

config = get_config('func_test')

class Utils:

    @classmethod
    def swauthPrep(self,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        return commands.getstatusoutput('gswauth-prep -A %s -U %s -K %s' % (authurl, user, key))

    @classmethod
    def addAccount(self,account_name,suffix=None, authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        if suffix is not None:
            return commands.getstatusoutput('gswauth-add-account %s -s %s -A %s -U %s -K %s' % (account_name, suffix, authurl, user, key))
        else:
            return commands.getstatusoutput('gswauth-add-account %s -A %s -U %s -K %s' % (account_name, authurl, user, key))

    @classmethod
    def deleteAccount(self,account_name,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        return commands.getstatusoutput('gswauth-delete-account %s -A %s -U %s -K %s' % (account_name, authurl, user, key))

    @classmethod
    def listAccounts(self,listtype=None,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        if listtype is not None:
            return commands.getstatusoutput('gswauth-list %s -A %s -U %s -K %s' % (listtype, authurl, user, key))
        else:
            return commands.getstatusoutput('gswauth-list -A %s -U %s -K %s' % (authurl, user, key))

    @classmethod
    def listUsers(self,account_name,listtype=None,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        if listtype is not None:
            return commands.getstatusoutput('gswauth-list %s %s -A %s -U %s -K %s'% (account_name, listtype, authurl, user, key))
        else:
            return commands.getstatusoutput('gswauth-list %s -A %s -U %s -K %s'% (account_name, authurl, user, key))

    @classmethod
    def addAdminUser(self,account_name,username,password,suffix=None,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        if suffix is not None:
            return commands.getstatusoutput('gswauth-add-user -a %s %s %s -s %s -A %s -U %s -K %s'% (account_name, username, password, suffix, authurl, user, key))
        else:
            return commands.getstatusoutput('gswauth-add-user -a %s %s %s -A %s -U %s -K %s'% (account_name, username, password, authurl, user, key))

    @classmethod
    def addUser(self,account_name,username,password,suffix=None,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        if suffix is not None:
            return commands.getstatusoutput('gswauth-add-user %s %s %s -s %s -A %s -U %s -K %s'% (account_name, username, password, suffix, authurl, user, key))
        else:
            return commands.getstatusoutput('gswauth-add-user %s %s %s -A %s -U %s -K %s'% (account_name, username, password, authurl, user, key))

    @classmethod
    def addResellerAdminUser(self,account_name,username,password,suffix=None,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        if suffix is not None:
            return commands.getstatusoutput('gswauth-add-user -r %s %s %s -s %s -A %s -U %s -K %s'% (account_name, username, password, suffix, authurl, user, key))
        else:
            return commands.getstatusoutput('gswauth-add-user -r %s %s %s -A %s -U %s -K %s'% (account_name, username, password, authurl, user, key))

    @classmethod
    def deleteUser(self,account_name,username,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        return commands.getstatusoutput('gswauth-delete-user %s %s -A %s -U %s -K %s'% (account_name, username, authurl, user, key))

    @classmethod
    def listUserGroups(self,account_name,username,listtype=None,authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        if listtype is not None:
            return commands.getstatusoutput('gswauth-list %s %s %s -A %s -U %s -K %s'% (account_name, username, listtype, authurl, user, key))
        else:
            return commands.getstatusoutput('gswauth-list %s %s %s -A %s -U %s -K %s'% (account_name, username, listtype, authurl, user, key))

    @classmethod
    def cleanToken(self,option=None,value=None,authurl='http://127.0.0.1:8080/auth/', key=config['admin_key']):
        if option is None and value is None:
            return commands.getstatusoutput('gswauth-cleanup-tokens -A %s -K %s'% (authurl, key))
        elif option is not None and value is None:
            return commands.getstatusoutput('gswauth-cleanup-tokens --%s -A %s -K %s'% (option, authurl, key))
        else:
            return commands.getstatusoutput('gswauth-cleanup-tokens --%s %s -A %s -K %s'% (option, value, authurl, key))

    @classmethod
    def setAccountService(self, account, service, name, value, authurl='http://127.0.0.1:8080/auth/',user=config['admin_user'],key=config['admin_key']):
        return commands.getstatusoutput('gswauth-set-account-service %s %s %s %s -A %s -U %s -K %s'% (account, service, name, value, authurl, user, key))

    @classmethod
    def cleanAll(self):
        commands.getstatusoutput('sudo rm -rf '+os.path.join(config['devices'], config['gsmetadata_volume'], '*'))
        return commands.getstatusoutput('sudo rm -rf '+os.path.join(config['devices'], config['gsmetadata_volume'], '.*'))


class TestSwauthPrep(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        Utils.cleanAll()

    def testSwauthPrep(self):
        (status,output)=Utils.swauthPrep()
        self.assertEqual(status, 0, 'swauth prep failed with valid credentials'+output)

        (status,output)=Utils.swauthPrep(key='')
        self.assertEqual('Usage' in output,True, 'Invalid swauth-prep request accepted(no key provided): '+output)

        (status,output)=Utils.swauthPrep(key='notavalidkey')
        self.assertNotEqual(status, 0, 'Invalid swauth-prep request accepted(wrong key provided):'+output)
        self.assertEqual('gswauth preparation failed: 401 Unauthorized: Invalid user/key provided' \
                         in output,True, 'Invalid swauth-prep request accepted: '+output)

        (status,output)=Utils.swauthPrep(authurl='http://127.0.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid swauth-prep request accepted(wrong admin-url provided): %s' % output)

        (status,output)=Utils.swauthPrep(authurl='http://127.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid swauth-prep request accepted(wrong admin-url provided): %s' % output)
        #TODO:More cases for invalid url and admin user

    def testAddAccountWithoutSwauthPrep(self):
        #Try to add account without running gswauth-prep
        Utils.cleanAll()
        (status,output)=Utils.addAccount('test')
        self.assertNotEqual(status, 0, 'account added without running gswauth-prep '+output)
        self.assertEqual('Account creation failed: 500 Server Error' \
                         in output,True, 'account added without running gswauth-prep '+output)


class TestAccount(unittest.TestCase):

    def setUp(self):
        (status,output)=Utils.swauthPrep()
        self.assertEqual(status, 0, 'setup swauth-prep failed'+output)

    def tearDown(self):
        Utils.cleanAll()

    def setTestAccUserEnv(self):
        (status,output)=Utils.addAccount('test')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addResellerAdminUser('test','re_admin','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addAdminUser('test','admin','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addUser('test','tester','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)

    def setTest2AccUserEnv(self):
        (status,output)=Utils.addAccount('test2')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addResellerAdminUser('test2','re_admin','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addAdminUser('test2','admin','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addUser('test2','tester','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)

    def testAddAccount(self):
        (status,output)=Utils.addAccount('test')
        self.assertEqual(status, 0, 'account creation failed'+output)

        (status,output)=Utils.addAccount('accountvolumedoesnotexist')
        self.assertEqual(status, 0, 'account creation failed std err was: '+output)

        (status,output)=Utils.addAccount('testnokey',key='')
        self.assertEqual('Usage:' in output, True, 'Invalid account creation request accepted : '+output)

        (status,output)=Utils.addAccount('testinvalidkey',key='invalidkey')
        self.assertEqual('Account creation failed: 401 Unauthorized: Invalid user/key provided' \
                                         in output,True, 'Invalid account creation request accepted: '+output)

        (status,output)=Utils.addAccount('test2', authurl='http://127.0.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid account creation request accepted(wrong admin-url provided): %s' % output)

        (status,output)=Utils.addAccount('test2', authurl='http://127.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid account creation request accepted(wrong admin-url provided): %s' % output)

    def testAddAccountNonSuperAdminUsers(self):
        #set test account with all types of user
        self.setTestAccUserEnv()
        #try to add another account with all type of users
        (status,output)=Utils.addAccount('accbyreselleradmin',user='test:re_admin',key='testing')
        self.assertEqual(status, 0, 'account creation failed with re_admin user: '+output)

        (status,output)=Utils.addAccount('accbyadmin',user='test:admin',key='testing')
        self.assertNotEqual(status, 0, 'account creation success with admin user: '+output)
        self.assertEqual('Account creation failed: 403 Forbidden: Insufficient privileges' in output,True, 'account creation success with admin user: '+output)

        (status,output)=Utils.addAccount('accbyuser',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 'account creation success with regular user: '+output)
        self.assertEqual('Account creation failed: 403 Forbidden: Insufficient privileges' \
                         in output,True, 'account creation success with regular user: '+output)

    def testDeleteAccount(self):
        #add test account with no users
        (status,output)=Utils.addAccount('test')
        self.assertEqual(status, 0, 'account creation failed for test account'+output)

        #set test2 account with all type of users
        self.setTest2AccUserEnv()

        #valid request to delete an account with no users
        (status,output)=Utils.deleteAccount('test')
        self.assertEqual(status, 0, 'account deletion failed for test account'+output)

        #Invalid request to delete an account with users
        (status,output)=Utils.deleteAccount('test2')
        self.assertNotEqual(status, 0, 'account deletion succeeded for acc with active users'+output)
        self.assertEqual('Delete account failed: 409 Conflict: Account test2 contains active users. Delete all users first.' \
                         in output,True, 'account deletion failed for test account'+output)

        #delete all users in above account and then try again
        (status,output) = Utils.deleteUser('test2','tester')
        self.assertEqual(status, 0, 'setTestDeleteAccountEnv'+output)

        (status,output) = Utils.deleteUser('test2','admin')
        self.assertEqual(status, 0, 'setTestDeleteAccountEnv'+output)

        (status,output) = Utils.deleteUser('test2','re_admin')
        self.assertEqual(status, 0, 'setTestDeleteAccountEnv'+output)

        (status,output)=Utils.deleteAccount('test2')
        self.assertEqual(status, 0, 'account deletion failed for test2 account'+output)

        (status,output)=Utils.deleteAccount('accountdoesnotexist')
        self.assertNotEqual(status, 0, 'account deletion failed for accountdoesnotexist'+output)
        self.assertEqual('Delete account failed: 404 Not Found: Account accountdoesnotexist does not exist' in output,True, 'account deletion failed for test account'+output)

        (status,output)=Utils.deleteAccount('test3', authurl='http://127.0.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid deletion request accepted(wrong admin-url provided): %s' % output)

        (status,output)=Utils.deleteAccount('test3', authurl='http://127.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid deletion request accepted(wrong admin-url provided): %s' % output)

    def testDeleteAccountNonSuperAdminUsers(self):
        #set test account with all types of user
        self.setTestAccUserEnv()

        #try to add another account with all type of users
        Utils.addAccount('accbysuperadminforreadmin')
        (status,output)=Utils.deleteAccount('accbysuperadminforreadmin',user='test:re_admin',key='testing')
        self.assertEqual(status, 0, 'account deletion failed with re_admin user: '+output)

        #TODO:uncomment following case when fix is there
        '''
        Utils.addAccount('accbysuperadminforadmin')
        (status,output)=Utils.deleteAccount('accbysuperadminforadmin',user='test:admin',key='testing')
        self.assertNotEqual(status, 0, 'account deletion success with admin user: '+output)
        self.assertEqual('Delete account failed: 403 Forbidden: Insufficient privileges' \
                         in output,True, 'account deletion success with admin user: '+output)
        '''

        Utils.addAccount('accbysuperadminforuser')
        (status,output)=Utils.deleteAccount('accbysuperadminforuser',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 'account creation success with regular user: '+output)
        self.assertEqual('Delete account failed: 403 Forbidden: Insufficient privileges' \
                         in output,True, 'account deletion success with regular user: '+output)

    def testListAcounts(self):
        (status,output)=Utils.addAccount('test')
        self.assertEqual(status, 0, 'account creation failed'+output)

        (status,output)=Utils.listAccounts()
        self.assertEqual(output,
            '+----------+\n| Accounts |\n+----------+\n|   test   |\n+----------+',
            'swauth-list failed:\n%s' % output)

        (status,output)=Utils.listAccounts(authurl='http://127.0.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid list request accepted(wrong admin-url provided): %s' % output)

        (status,output)=Utils.listAccounts(authurl='http://127.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid list request accepted(wrong admin-url provided): %s' % output)

        (status,output)=Utils.listAccounts('-j')
        self.assertEqual(output,
            '{"accounts": [{"name": "test"}]}',
            'swauth-list failed for json option:\n%s' % output)

        (status,output)=Utils.listAccounts('-p')
        self.assertEqual(output,
            'test',
            'swauth-list failed for plain-text option:\n%s' % output)

    def testListAcountsNonSuperAdminUsers(self):
        #set test acc with all type of users
        self.setTestAccUserEnv()

        (status,output)=Utils.listAccounts(user='test:re_admin',key='testing')
        self.assertEqual(status, 0, 'account listing failed with re_admin user: '+output)
        self.assertEqual(output,
            '+----------+\n| Accounts |\n+----------+\n|   test   |\n+----------+',
            'swauth-list failed:\n%s' % output)

        (status,output)=Utils.listAccounts(user='test:admin',key='testing')
        self.assertNotEqual(status, 0, 'account listing success with admin user: '+output)
        self.assertEqual('List failed: 403 Forbidden: Insufficient privileges' \
                         in output,True, 'account listing success with admin user: '+output)

        (status,output)=Utils.listAccounts(user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 'account listing success with regular user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'account listing success with regular user: '+output)

class TestUser(unittest.TestCase):

    def setUp(self):
        (status,output)=Utils.swauthPrep()
        self.assertEqual(status, 0, 'setup swauth-prep failed'+output)

    def tearDown(self):
        Utils.cleanAll()

    def setTestAccUserEnv(self):
        (status,output)=Utils.addAccount('test')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addResellerAdminUser('test','re_admin','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addAdminUser('test','admin','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addUser('test','tester','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)

    def setTest2AccUserEnv(self):
        (status,output)=Utils.addAccount('test2')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addResellerAdminUser('test2','re_admin','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addAdminUser('test2','admin','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addUser('test2','tester','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)

    def testaddUser(self):
        #add test acc
        (status,output)=Utils.addAccount('test')
        self.assertEqual(status, 0, 'setTestaddAdminUserEnv (add test account) failed'+output)

        (status,output) = Utils.addAdminUser('test','testadminuser','testadminuser')
        self.assertEqual(status, 0, 'user addition failed'+output)

        (status,output) = Utils.addUser('test','testuser','testuser')
        self.assertEqual(status, 0, 'user addition failed'+output)

        (status,output) = Utils.addResellerAdminUser('test','testreselleradminuser','testreselleradminuser')
        self.assertEqual(status, 0, 'user addition failed'+output)

        (status,output) = Utils.addAdminUser('test', '', '')
        self.assertEqual('Usage:' in output, True, 'Invalid user creation request accepted: '+output)

        (status,output) = Utils.addAdminUser('test', 'testcli', '')
        self.assertEqual('Usage:' in output, True, 'Invalid user creation request accepted'+output)

        (status,output) = Utils.addAdminUser('test', '', 'testcli')
        self.assertEqual('Usage:' in output, True, 'Invalid user creation request accepted'+output)

        (status,output) = Utils.addAdminUser('accountdoesnotexist', 'testcli', 'testcli')
        self.assertEqual(status, 0, 'User creation request failed, where accountdoesnotexist: '+output)

        (status,output)=Utils.addAdminUser('test', 'admin2', 'adminpwd', authurl='http://127.0.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid add user request accepted(wrong admin-url provided): %s' % output)

        (status,output)=Utils.addAdminUser('test', 'admin2', 'adminpwd', authurl='http://127.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid add user request accepted(wrong admin-url provided): %s' % output)

    def testAddUserNonSuperAdminUsers (self):
        #setup test,testr accounts with all user types
        self.setTestAccUserEnv()
        self.setTest2AccUserEnv()

        #try to add another reseller_admin users with all type of users
        #TODO:Uncomment Following,Possible Bug:403 should be return instead of current 401
        '''
        (status,output)=Utils.addResellerAdminUser('test', 're_adminwithreadmin', 'testing', user='test:re_admin', key='testing')
        self.assertNotEqual(status, 0, 're_admin creation succeeded with re_admin user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin creation succeeded with re_admin user: '+output)

        (status,output)=Utils.addResellerAdminUser('test', 're_adminwithadmin', 'testing', user='test:admin', key='testing')
        self.assertNotEqual(status, 0, 're_admin creation succeeded with admin user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin creation succeeded with admin user: '+output)

        (status,output)=Utils.addResellerAdminUser('test', 're_adminwithuser', 'testing', user='test:tester', key='testing')
        self.assertNotEqual(status, 0, 're_admin creation succeeded with regular user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin creation succeeded with regular user: '+output)

        (status,output)=Utils.addResellerAdminUser('test2', 're_adminwithreadmin', 'testing', user='test:re_admin', key='testing')
        self.assertNotEqual(status, 0, 're_admin creation succeeded with re_admin user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin creation succeeded with re_admin user: '+output)

        (status,output)=Utils.addResellerAdminUser('test2', 're_adminwithadmin', 'testing', user='test:admin', key='testing')
        self.assertNotEqual(status, 0, 're_admin creation succeeded with admin user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin creation succeeded with admin user: '+output)

        (status,output)=Utils.addResellerAdminUser('test2', 're_adminwithuser', 'testing', user='test:tester', key='testing')
        self.assertNotEqual(status, 0, 're_admin creation succeeded with regular user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin creation succeeded with regular user: '+output)

        #update the password with own credential
        (status,output)=Utils.addResellerAdminUser('test', 're_adminwithreadmin', 'testingupdated', user='test:re_admin', key='testing')
        self.assertNotEqual(status, 0, 're_admin update password succeeded with own credentials: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin update password succeeded with own credentials: '+output)
        '''
        #try to add another admin users with all type of users
        (status,output)=Utils.addAdminUser('test', 'adminwithreadmin', 'testing', user='test:re_admin', key='testing')
        self.assertEqual(status, 0, 'admin creation failed with re_admin user: '+output)

        (status,output)=Utils.addAdminUser('test', 'adminwithreadmin', 'testing', user='test:admin', key='testing')
        self.assertEqual(status, 0, 'admin creation failed with admin user: '+output)

        (status,output)=Utils.addAdminUser('test', 'adminwithuser', 'testing', user='test:tester', key='testing')
        self.assertNotEqual(status, 0, 'admin creation succeeded with regular user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'admin creation succeeded with regular user: '+output)

        (status,output)=Utils.addAdminUser('test2', 'adminwithreadminofotheraccount', 'testing', user='test:re_admin', key='testing')
        self.assertEqual(status, 0, 'admin creation failed with re_admin user of other account: '+output)

        (status,output)=Utils.addAdminUser('test2', 'adminwithadminofotheraccount', 'testing', user='test:admin', key='testing')
        self.assertNotEqual(status, 0, 'admin creation succeeded with admin user of other acc: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'admin creation succeeded with admin user of other acc: '+output)

        (status,output)=Utils.addAdminUser('test2', 'adminwithuserfotheraccount', 'testing', user='test:tester', key='testing')
        self.assertNotEqual(status, 0, 'admin creation succeeded with user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'admin creation succeeded with user of other account: '+output)

        #update password of own admin account
        (status,output)=Utils.addAdminUser('test', 'admin', 'testingupdated', user='test:admin', key='testing')
        self.assertEqual(status, 0, 'admin password update failed with own credentials: '+output)
        #undo above password change
        (status,output)=Utils.addAdminUser('test', 'admin', 'testing', user='test:admin', key='testingupdated')
        self.assertEqual(status, 0, 'admin password update failed with own credentials: '+output)

        #try to add another regular users with all type of users
        (status,output)=Utils.addUser('test', 'adduserwithre_admin', 'testing', user='test:re_admin', key='testing')
        self.assertEqual(status, 0, 'regular user creation with re_admin credentials failed: '+output)

        (status,output)=Utils.addUser('test', 'adduserwithadmin', 'testing', user='test:admin', key='testing')
        self.assertEqual(status, 0, 'regular user creation with admin credentials failed: '+output)

        (status,output)=Utils.addUser('test', 'adduserwithuser', 'testing', user='test:tester', key='testing')
        self.assertNotEqual(status, 0, 'regular user creation with regular user credentials succeded: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'regular user creation with regular user credentials succeded: '+output)

        (status,output)=Utils.addUser('test2', 'adduserwithreadminofotheraccount', 'testing', user='test:re_admin', key='testing')
        self.assertEqual(status, 0, 'user creation failed with re_admin user of other account: '+output)

        (status,output)=Utils.addUser('test2', 'adduserwithadminofotheraccount', 'testing', user='test:admin', key='testing')
        self.assertNotEqual(status, 0, 'user creation succeeded with admin user of other acc: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'user creation succeeded with admin user of other acc: '+output)

        (status,output)=Utils.addUser('test2', 'adminwithuserfotheraccount', 'testing', user='test:tester', key='testing')
        self.assertNotEqual(status, 0, 'user creation succeeded with user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'user creation succeeded with user of other account: '+output)

    def testDeleteUser(self):
        #set test acc
        self.setTestAccUserEnv()

        (status,output) = Utils.deleteUser('test','admin')
        self.assertEqual(status, 0, 'valid user deletion failed:'+output)

        (status,output) = Utils.deleteUser('test','tester')
        self.assertEqual(status, 0, 'valid user deletion failed:'+output)

        (status,output) = Utils.deleteUser('test','re_admin')
        self.assertEqual(status, 0, 'valid user deletion failed:'+output)

        (status,output) = Utils.deleteUser('test', '')
        self.assertEqual('Usage:' in output, True, 'Invalid user deletion request accepted : '+output)

        (status,output) = Utils.deleteUser('','testcli')
        self.assertEqual('Usage:' in output, True, 'Invalid user deletion request accepted : '+output)

        (status,output) = Utils.deleteUser('test', 'userdoesnotexist')
        self.assertNotEqual(status, 0, 'Invalid user deletion request accepted,userdoesnotexist:'+output)

        (status,output) = Utils.deleteUser('accountisnothere', 'testcli')
        self.assertNotEqual(status, 0, 'Invalid user deletion request accepted, accountdoesnotexist:'+output)
        #TODO:more testcases?
        (status,output)=Utils.deleteUser('test', 'admin2', authurl='http://127.0.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid delete user request accepted(wrong admin-url provided): %s' % output)

        (status,output)=Utils.deleteUser('test', 'admin2', authurl='http://127.0.1:80/auth/')
        self.assertEqual('Check that the admin_url is valid' in output, True,
            'Invalid delete user request accepted(wrong admin-url provided): %s' % output)

    def testDeleteUserNonSuperAdminUsers(self):
        #set test, test2 acc with all type of users
        self.setTestAccUserEnv()
        self.setTest2AccUserEnv()
        #try to delete reseller_admin users with all type of users
        Utils.addResellerAdminUser('test', 're_admintobedeletedbyotherusers1', 'testing')
        (status,output) = Utils.deleteUser('test', 're_admintobedeletedbyotherusers1',user='test:re_admin',key='testing')
        self.assertNotEqual(status, 0, 're_admin deletion succeeded with re_admin user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin deletion succeeded with re_admin user: '+output)

        Utils.addResellerAdminUser('test', 're_admintobedeletedbyotherusers2', 'testing')
        (status,output) = Utils.deleteUser('test', 're_admintobedeletedbyotherusers2',user='test:admin',key='testing')
        self.assertNotEqual(status, 0, 're_admin deletion succeeded with admin user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin deletion succeeded with admin user: '+output)

        Utils.addResellerAdminUser('test', 're_admintobedeletedbyotherusers3', 'testing')
        (status,output) = Utils.deleteUser('test', 're_admintobedeletedbyotherusers3',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 're_admin deletion succeeded with regular user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin deletion succeeded with user: '+output)

        Utils.addResellerAdminUser('test2', 're_admintobedeletedbyotheraccountusers1', 'testing')
        (status,output) = Utils.deleteUser('test2', 're_admintobedeletedbyotheraccountusers1',user='test:re_admin',key='testing')
        self.assertNotEqual(status, 0, 're_admin deletion succeeded with re_admin user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin deletion succeeded with re_admin user of other account: '+output)

        Utils.addResellerAdminUser('test2', 're_admintobedeletedbyotheraccountusers2', 'testing')
        (status,output) = Utils.deleteUser('test2', 're_admintobedeletedbyotheraccountusers2',user='test:admin',key='testing')
        self.assertNotEqual(status, 0, 're_admin deletion succeeded with admin user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin deletion succeeded with admin user of other account: '+output)

        Utils.addResellerAdminUser('test2', 're_admintobedeletedbyotheraccountusers3', 'testing')
        (status,output) = Utils.deleteUser('test2', 're_admintobedeletedbyotheraccountusers3',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 're_admin deletion succeeded with regular user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 're_admin deletion succeeded with user of other account: '+output)

        #delete/de-active own re_admin account
        Utils.addAdminUser('test', 're_admintobedeletedbyitself', 'testing')
        (status,output) = Utils.deleteUser('test', 're_admintobedeletedbyitself',user='test:re_admintobedeletedbyitself',key='testing')
        self.assertEqual(status, 0, 're_admin deletion failed with own credentials : '+output)

        #try to delete admin users with all type of users
        Utils.addAdminUser('test', 'admintobedeletedbyotherusers1', 'testing')
        (status,output) = Utils.deleteUser('test', 'admintobedeletedbyotherusers1',user='test:re_admin',key='testing')
        self.assertEqual(status, 0, 'admin deletion failed with re_admin user: '+output)

        Utils.addAdminUser('test', 'admintobedeletedbyotherusers2', 'testing')
        (status,output) = Utils.deleteUser('test', 'admintobedeletedbyotherusers2',user='test:admin',key='testing')
        self.assertEqual(status, 0, 'admin deletion failed with admin user: '+output)

        Utils.addAdminUser('test', 'admintobedeletedbyotherusers3', 'testing')
        (status,output) = Utils.deleteUser('test', 'admintobedeletedbyotherusers3',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 'admin deletion succeeded with regular user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'admin deletion succeeded with regular user: '+output)

        Utils.addAdminUser('test2', 'admintobedeletedbyotheraccountusers1', 'testing')
        (status,output) = Utils.deleteUser('test2', 'admintobedeletedbyotheraccountusers1',user='test:re_admin',key='testing')
        self.assertEqual(status, 0, 'admin deletion failed with re_admin user of other account: '+output)

        Utils.addAdminUser('test2', 'admintobedeletedbyotheraccountusers2', 'testing')
        (status,output) = Utils.deleteUser('test2', 'admintobedeletedbyotheraccountusers2',user='test:admin',key='testing')
        self.assertNotEqual(status, 0, 'admin deletion succeeded with admin user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'admin deletion succeeded with admin user of other account: '+output)

        Utils.addAdminUser('test2', 'admintobedeletedbyotheraccountusers3', 'testing')
        (status,output) = Utils.deleteUser('test2', 'admintobedeletedbyotheraccountusers3',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 'admin deletion succeeded with regular user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'admin deletion succeeded with regular user of other account: '+output)

        #delete/de-active own admin account
        Utils.addAdminUser('test', 'admintobedeletedbyitself', 'testing')
        (status,output) = Utils.deleteUser('test', 'admintobedeletedbyitself',user='test:admintobedeletedbyitself',key='testing')
        self.assertEqual(status, 0, 'admin deletion failed with own credentials : '+output)

        #try to delete another regular users with all type of users
        Utils.addUser('test', 'usertobedeletedbyotherusers1', 'testing')
        (status,output) = Utils.deleteUser('test', 'usertobedeletedbyotherusers1',user='test:re_admin',key='testing')
        self.assertEqual(status, 0, 'user deletion failed with re_admin user: '+output)

        Utils.addUser('test', 'usertobedeletedbyotherusers2', 'testing')
        (status,output) = Utils.deleteUser('test', 'usertobedeletedbyotherusers2',user='test:admin',key='testing')
        self.assertEqual(status, 0, 'user deletion failed with admin user: '+output)

        Utils.addUser('test', 'usertobedeletedbyotherusers3', 'testing')
        (status,output) = Utils.deleteUser('test', 'usertobedeletedbyotherusers3',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 'user deletion succeeded with regular user: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'user deletion succeeded with regular user: '+output)

        Utils.addUser('test2', 'usertobedeletedbyotheraccountusers1', 'testing')
        (status,output) = Utils.deleteUser('test2', 'usertobedeletedbyotheraccountusers1',user='test:re_admin',key='testing')
        self.assertEqual(status, 0, 'user deletion failed with re_admin user of other account: '+output)

        Utils.addUser('test2', 'usertobedeletedbyotheraccountusers2', 'testing')
        (status,output) = Utils.deleteUser('test2', 'usertobedeletedbyotheraccountusers2',user='test:admin',key='testing')
        self.assertNotEqual(status, 0, 'user deletion succeeded with admin user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'user deletion succeeded with admin user of other account: '+output)

        Utils.addUser('test2', 'usertobedeletedbyotheraccountusers3', 'testing')
        (status,output) = Utils.deleteUser('test2', 'usertobedeletedbyotheraccountusers3',user='test:tester',key='testing')
        self.assertNotEqual(status, 0, 'user deletion succeeded with regular user of other account: '+output)
        self.assertEqual('403 Forbidden' in output,True, 'user deletion succeeded with regular user of other account: '+output)

        #delete/de-active own admin account
        Utils.addAdminUser('test', 'usertobedeletedbyitself', 'testing')
        (status,output) = Utils.deleteUser('test', 'usertobedeletedbyitself',user='test:usertobedeletedbyitself',key='testing')
        self.assertEqual(status, 0, 'user deletion failed with own credentials : '+output)

    def testChangeKey(self):
        # Create account and users
        (status, output) = Utils.addAccount('test')
        self.assertEqual(status, 0, 'Account creation failed: ' + output)

        (status, output) = Utils.addAdminUser('test', 'admin', 'password')
        self.assertEqual(status, 0, 'User addition failed: ' + output)

        (status, output) = Utils.addUser('test', 'user', 'password')
        self.assertEqual(status, 0, 'User addition failed: ' + output)

        (status, output) = Utils.addResellerAdminUser('test', 'radmin', 'password')
        self.assertEqual(status, 0, 'User addition failed: ' + output)

        # Change acccount admin password/key
        (status, output) = Utils.addAdminUser('test', 'admin', 'new_password', user='test:admin', key='password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # Change regular user password/key
        (status, output) = Utils.addUser('test', 'user', 'new_password', user='test:user', key='password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # Change reseller admin password/key
        (status, output) = Utils.addResellerAdminUser('test', 'radmin', 'new_password', user='test:radmin', key='password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # To verify that password was changed for real, re-run the above commands, but with the new password
        # Change acccount admin password/key using the new password
        (status, output) = Utils.addAdminUser('test', 'admin', 'password', user='test:admin', key='new_password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # Change regular user password/key using the new password
        (status, output) = Utils.addUser('test', 'user', 'password', user='test:user', key='new_password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # Change reseller admin password/key using the new password
        (status, output) = Utils.addResellerAdminUser('test', 'radmin', 'password', user='test:radmin', key='new_password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # Make sure that regular user cannot upgrade to admin
        (status, output) = Utils.addAdminUser('test', 'user', 'password', user='test:user', key='password')
        self.assertEqual('User creation failed' in output, True, 'Update key failed: ' + output)

        # Make sure that regular user cannot upgrade to reseller_admin
        (status, output) = Utils.addResellerAdminUser('test', 'user', 'password', user='test:user', key='password')
        self.assertEqual('User creation failed' in output, True, 'Update key failed: ' + output)

        # Make sure admin cannot update himself to reseller_admin
        (status, output) = Utils.addResellerAdminUser('test', 'admin', 'password', user='test:admin', key='password')
        self.assertEqual('User creation failed' in output, True, 'Update key failed: ' + output)

        # Account admin changing regular user password/key
        (status, output) = Utils.addUser('test', 'user', 'new_password', user='test:admin', key='password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)
        # Verify by running the command with new password
        (status, output) = Utils.addUser('test', 'user', 'password', user='test:user', key='new_password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # Reseller admin changing regular user password/key
        (status, output) = Utils.addUser('test', 'user', 'new_password', user='test:radmin', key='password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)
        # Verify by running the command with new password
        (status, output) = Utils.addUser('test', 'user', 'password', user='test:user', key='new_password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)

        # Reseller admin changing account admin password/key
        (status, output) = Utils.addAdminUser('test', 'admin', 'new_password', user='test:radmin', key='password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)
        # Verify by running the command with new password
        (status, output) = Utils.addAdminUser('test', 'admin', 'password', user='test:admin', key='new_password')
        self.assertEqual(status, 0, 'Update key failed: ' + output)


class TestCleanUPToken(unittest.TestCase):

    def setUp(self):
        (status,output)=Utils.swauthPrep()
        self.assertEqual(status, 0, 'setup swauth-prep failed'+output)

    def tearDown(self):
        Utils.cleanAll()

    def setTestAccUserEnv(self):
        (status,output)=Utils.addAccount('test')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addResellerAdminUser('test','re_admin','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addAdminUser('test','admin','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)
        (status,output)=Utils.addUser('test','tester','testing')
        self.assertEqual(status, 0, 'test accUser creation failed env'+output)

    def setTest2AccUserEnv(self):
        (status,output)=Utils.addAccount('test2')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addResellerAdminUser('test2','re_admin','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addAdminUser('test2','admin','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)
        (status,output)=Utils.addUser('test2','tester','testing')
        self.assertEqual(status, 0, 'test2 accUser creation failed env'+output)

    def testCleanUPToken(self):
        self.setTestAccUserEnv()
        self.setTest2AccUserEnv()

        #cleanup various validation
        (status,output)=Utils.cleanToken(key='')
        self.assertNotEqual(status, 0, 'clean up success without key'+output)
        self.assertEqual('Usage:' in output,True, 'clean up success without key: '+output)

        #validate the admin-user option is not working here
        (status,output)=Utils.cleanToken(option='admin-user', value='.super_admin')
        self.assertNotEqual(status, 0, 'clean up success with a username'+output)
        self.assertEqual('Usage:' in output,True, 'clean up success with a username: '+output)

        (status,output)=Utils.cleanToken(key='noavalidsuperadminkey')
        self.assertNotEqual(status, 0, 'clean up success with wrong super_admin key'+output)
        self.assertEqual('401 Unauthorized' in output,True, 'clean up success with wrong super_admin key: '+output)

        #cleanup token with no options
        (status,output)=Utils.cleanToken()
        self.assertEqual(status, 0, 'clean up failed with no option'+output)

        #cleanup token with purge option
        (status,output)=Utils.cleanToken(option='purge', value='test')
        self.assertEqual(status, 0, 'clean up failed with purge option'+output)

        #cleanup token with purge option no valid account name
        #TODO:review following https://bugs.launchpad.net/gluster-swift/+bug/1271555
        (status,output)=Utils.cleanToken(option='purge', value='accountnotvalid')
        self.assertNotEqual(status, 0, 'clean up failed with purge option'+output)

        #cleanup token with purge-all option
        (status,output)=Utils.cleanToken(option='purge-all')
        self.assertEqual(status, 0, 'clean up failed with purge-all option'+output)

        #cleanup token with -v option
        (status,output)=Utils.cleanToken(option='verbose')
        self.assertEqual(status, 0, 'clean up failed with verbose option'+output)
        self.assertEqual('GET .token_0' in output and 'GET .token_f' in output,True,\
                          'clean up success without key: '+output)

        #cleanup token with token-life option
        (status,output)=Utils.cleanToken(option='token-life', value='500')
        self.assertEqual(status, 0, 'clean up failed with token-life option'+output)

        #cleanup token with sleep option
        (status,output)=Utils.cleanToken(option='sleep', value='500')
        self.assertEqual(status, 0, 'clean up failed with sleep option'+output)

        #TODO:revisit below two cases after fix for
        #https://bugs.launchpad.net/gluster-swift/+bug/1271550
        #cleanup token with token-life option non numeric value
        (status,output)=Utils.cleanToken(option='token-life', value='notanumaric')
        self.assertNotEqual(status, 0, 'clean up success with token-life option token-life non numeric value'+output)
        self.assertEqual('ValueError' in output,True, 'clean up \
        success with token-life option non numeric value: '+output)

        #cleanup token with sleep option non numeric value
        (status,output)=Utils.cleanToken(option='sleep', value='notanumeric')
        self.assertNotEqual(status, 0, 'clean up failed with sleep option non numeric value'+output)
        self.assertEqual('ValueError' in output,True, 'clean up \
        success with token-life option non numeric value: '+output)

    def testSetAccountService(self):
        self.setTestAccUserEnv()
        self.setTest2AccUserEnv()

        #set-account-service asset all valid value
        (status,output)=Utils.setAccountService('test', 'storage', 'local', 'http://localhost:8080/v1/AUTH_test')
        self.assertEqual(status, 0, 'set account service fails with valid input'+output)
        (status,output)=Utils.listUsers('test', listtype='--json')
        self.assertEqual('{"services": {"storage": {"default": "local", "local": "http://localhost:8080/v1/AUTH_test"}}' in output,True, \
        'set account service success with valid input'+output)

        #invalid account
        (status,output)=Utils.setAccountService('accountdoesnotexist', 'storage', 'local', 'http://localhost:8080/v1/AUTH_test')
        self.assertNotEqual(status, 0, 'set account service success with invalid accountname'+output)
        self.assertEqual('Service set failed: 404 Not Found' in output,True, 'set account service success with invalid accountname'+output)

        #service name other than storage
        (status,output)=Utils.setAccountService('test', 'st', 'local', 'http://localhost:8080/v1/AUTH_test')
        self.assertEqual(status, 0, 'set account service success with service name other than storage'+output)
        (status,output)=Utils.listUsers('test', listtype='--json')
        self.assertEqual('"st": {"local": "http://localhost:8080/v1/AUTH_test"}}' in output,True, \
        'set account service success with service name other than storage'+output)

        #name other than local
        (status,output)=Utils.setAccountService('test', 'storage', 'notlocal', 'http://localhost:8080/v1/AUTH_test')
        self.assertEqual(status, 0, 'set account service with name other than local failed'+output)
        (status,output)=Utils.listUsers('test', listtype='--json')
        self.assertEqual(' "notlocal": "http://localhost:8080/v1/AUTH_test"}' in output,True, \
        'set account service with name other than local failed'+output)

        #set default to point notlocal
        (status,output)=Utils.setAccountService('test', 'storage', 'default', 'notlocal')
        self.assertEqual(status, 0, 'set account service set default to  local failed'+output)
        (status,output)=Utils.listUsers('test', listtype='--json')
        self.assertEqual(' {"default": "notlocal", "notlocal": "http://localhost:8080/v1/AUTH_test"' in output,True, \
        'set account service set default to local failed'+output)

        #try to set account service with users other than .super_admin
        #reseller_admin
        (status,output)=Utils.setAccountService('test', 'storage', 'local', 'http://localhost:8080/v1/AUTH_test', user='test:re_admin', key='testing')
        self.assertEqual(status, 0, 'set account service fails re_admin user cred'+output)

        #admin user
        (status,output)=Utils.setAccountService('test', 'storage', 'local', 'http://localhost:8080/v1/AUTH_test', user='test:admin', key='testing')
        self.assertNotEqual(status, 0, 'set account service success with admin user cred'+output)
        #self.assertEqual('403 Forbidden' in output,True, 'set account service success with admin user cred'+output)

        #regular user
        (status,output)=Utils.setAccountService('test', 'storage', 'local', 'http://localhost:8080/v1/AUTH_test', user='test:tester', key='testing')
        self.assertNotEqual(status, 0, 'set account service success with regular user cred'+output)
        #self.assertEqual('403 Forbidden' in output,True, 'set account service success with admin user cred'+output)