|
@@ -2646,6 +2646,390 @@ class TestUserEndpoint(FunctionalTest):
|
2646
|
2646
|
)
|
2647
|
2647
|
|
2648
|
2648
|
|
|
2649
|
+class TestUsersEndpoint(FunctionalTest):
|
|
2650
|
+ # -*- coding: utf-8 -*-
|
|
2651
|
+ """
|
|
2652
|
+ Tests for GET /api/v2/users/{user_id}
|
|
2653
|
+ """
|
|
2654
|
+ fixtures = [BaseFixture]
|
|
2655
|
+
|
|
2656
|
+ def test_api__get_user__ok_200__admin(self):
|
|
2657
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
2658
|
+ admin = dbsession.query(models.User) \
|
|
2659
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
2660
|
+ .one()
|
|
2661
|
+ uapi = UserApi(
|
|
2662
|
+ current_user=admin,
|
|
2663
|
+ session=dbsession,
|
|
2664
|
+ config=self.app_config,
|
|
2665
|
+ )
|
|
2666
|
+ gapi = GroupApi(
|
|
2667
|
+ current_user=admin,
|
|
2668
|
+ session=dbsession,
|
|
2669
|
+ config=self.app_config,
|
|
2670
|
+ )
|
|
2671
|
+ groups = [gapi.get_one_with_name('users')]
|
|
2672
|
+ test_user = uapi.create_user(
|
|
2673
|
+ email='test@test.test',
|
|
2674
|
+ password='pass',
|
|
2675
|
+ name='bob',
|
|
2676
|
+ groups=groups,
|
|
2677
|
+ timezone='Europe/Paris',
|
|
2678
|
+ do_save=True,
|
|
2679
|
+ do_notify=False,
|
|
2680
|
+ )
|
|
2681
|
+ uapi.save(test_user)
|
|
2682
|
+ transaction.commit()
|
|
2683
|
+ user_id = int(test_user.user_id)
|
|
2684
|
+
|
|
2685
|
+ self.testapp.authorization = (
|
|
2686
|
+ 'Basic',
|
|
2687
|
+ (
|
|
2688
|
+ 'admin@admin.admin',
|
|
2689
|
+ 'admin@admin.admin'
|
|
2690
|
+ )
|
|
2691
|
+ )
|
|
2692
|
+ res = self.testapp.get(
|
|
2693
|
+ '/api/v2/users',
|
|
2694
|
+ status=200
|
|
2695
|
+ )
|
|
2696
|
+ res = res.json_body
|
|
2697
|
+ assert len(res) == 2
|
|
2698
|
+ assert res[0]['user_id'] == admin.user_id
|
|
2699
|
+ assert res[0]['public_name'] == admin.display_name
|
|
2700
|
+ assert res[0]['avatar_url'] is None
|
|
2701
|
+
|
|
2702
|
+ assert res[1]['user_id'] == test_user.user_id
|
|
2703
|
+ assert res[1]['public_name'] == test_user.display_name
|
|
2704
|
+ assert res[1]['avatar_url'] is None
|
|
2705
|
+
|
|
2706
|
+ def test_api__get_user__err_403__normal_user(self):
|
|
2707
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
2708
|
+ admin = dbsession.query(models.User) \
|
|
2709
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
2710
|
+ .one()
|
|
2711
|
+ uapi = UserApi(
|
|
2712
|
+ current_user=admin,
|
|
2713
|
+ session=dbsession,
|
|
2714
|
+ config=self.app_config,
|
|
2715
|
+ )
|
|
2716
|
+ gapi = GroupApi(
|
|
2717
|
+ current_user=admin,
|
|
2718
|
+ session=dbsession,
|
|
2719
|
+ config=self.app_config,
|
|
2720
|
+ )
|
|
2721
|
+ groups = [gapi.get_one_with_name('users')]
|
|
2722
|
+ test_user = uapi.create_user(
|
|
2723
|
+ email='test@test.test',
|
|
2724
|
+ password='pass',
|
|
2725
|
+ name='bob',
|
|
2726
|
+ groups=groups,
|
|
2727
|
+ timezone='Europe/Paris',
|
|
2728
|
+ do_save=True,
|
|
2729
|
+ do_notify=False,
|
|
2730
|
+ )
|
|
2731
|
+ uapi.save(test_user)
|
|
2732
|
+ transaction.commit()
|
|
2733
|
+ user_id = int(test_user.user_id)
|
|
2734
|
+
|
|
2735
|
+ self.testapp.authorization = (
|
|
2736
|
+ 'Basic',
|
|
2737
|
+ (
|
|
2738
|
+ 'test@test.test',
|
|
2739
|
+ 'pass'
|
|
2740
|
+ )
|
|
2741
|
+ )
|
|
2742
|
+ self.testapp.get(
|
|
2743
|
+ '/api/v2/users',
|
|
2744
|
+ status=403
|
|
2745
|
+ )
|
|
2746
|
+
|
|
2747
|
+
|
|
2748
|
+class TestKnownMembersEndpoint(FunctionalTest):
|
|
2749
|
+ # -*- coding: utf-8 -*-
|
|
2750
|
+ """
|
|
2751
|
+ Tests for GET /api/v2/users/{user_id}
|
|
2752
|
+ """
|
|
2753
|
+ fixtures = [BaseFixture]
|
|
2754
|
+
|
|
2755
|
+ def test_api__get_user__ok_200__admin__by_name(self):
|
|
2756
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
2757
|
+ admin = dbsession.query(models.User) \
|
|
2758
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
2759
|
+ .one()
|
|
2760
|
+ uapi = UserApi(
|
|
2761
|
+ current_user=admin,
|
|
2762
|
+ session=dbsession,
|
|
2763
|
+ config=self.app_config,
|
|
2764
|
+ )
|
|
2765
|
+ gapi = GroupApi(
|
|
2766
|
+ current_user=admin,
|
|
2767
|
+ session=dbsession,
|
|
2768
|
+ config=self.app_config,
|
|
2769
|
+ )
|
|
2770
|
+ groups = [gapi.get_one_with_name('users')]
|
|
2771
|
+ test_user = uapi.create_user(
|
|
2772
|
+ email='test@test.test',
|
|
2773
|
+ password='pass',
|
|
2774
|
+ name='bob',
|
|
2775
|
+ groups=groups,
|
|
2776
|
+ timezone='Europe/Paris',
|
|
2777
|
+ do_save=True,
|
|
2778
|
+ do_notify=False,
|
|
2779
|
+ )
|
|
2780
|
+ test_user2 = uapi.create_user(
|
|
2781
|
+ email='test2@test2.test2',
|
|
2782
|
+ password='pass',
|
|
2783
|
+ name='bob2',
|
|
2784
|
+ groups=groups,
|
|
2785
|
+ timezone='Europe/Paris',
|
|
2786
|
+ do_save=True,
|
|
2787
|
+ do_notify=False,
|
|
2788
|
+ )
|
|
2789
|
+ uapi.save(test_user)
|
|
2790
|
+ uapi.save(test_user2)
|
|
2791
|
+ transaction.commit()
|
|
2792
|
+ user_id = int(admin.user_id)
|
|
2793
|
+
|
|
2794
|
+ self.testapp.authorization = (
|
|
2795
|
+ 'Basic',
|
|
2796
|
+ (
|
|
2797
|
+ 'admin@admin.admin',
|
|
2798
|
+ 'admin@admin.admin'
|
|
2799
|
+ )
|
|
2800
|
+ )
|
|
2801
|
+ params = {
|
|
2802
|
+ 'acp': 'bob',
|
|
2803
|
+ }
|
|
2804
|
+ res = self.testapp.get(
|
|
2805
|
+ '/api/v2/users/{user_id}/known_members'.format(user_id=user_id),
|
|
2806
|
+ status=200,
|
|
2807
|
+ params=params,
|
|
2808
|
+ )
|
|
2809
|
+ res = res.json_body
|
|
2810
|
+ assert len(res) == 2
|
|
2811
|
+ assert res[0]['user_id'] == test_user.user_id
|
|
2812
|
+ assert res[0]['public_name'] == test_user.display_name
|
|
2813
|
+ assert res[0]['avatar_url'] is None
|
|
2814
|
+
|
|
2815
|
+ assert res[1]['user_id'] == test_user2.user_id
|
|
2816
|
+ assert res[1]['public_name'] == test_user2.display_name
|
|
2817
|
+ assert res[1]['avatar_url'] is None
|
|
2818
|
+
|
|
2819
|
+ def test_api__get_user__ok_200__admin__by_email(self):
|
|
2820
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
2821
|
+ admin = dbsession.query(models.User) \
|
|
2822
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
2823
|
+ .one()
|
|
2824
|
+ uapi = UserApi(
|
|
2825
|
+ current_user=admin,
|
|
2826
|
+ session=dbsession,
|
|
2827
|
+ config=self.app_config,
|
|
2828
|
+ )
|
|
2829
|
+ gapi = GroupApi(
|
|
2830
|
+ current_user=admin,
|
|
2831
|
+ session=dbsession,
|
|
2832
|
+ config=self.app_config,
|
|
2833
|
+ )
|
|
2834
|
+ groups = [gapi.get_one_with_name('users')]
|
|
2835
|
+ test_user = uapi.create_user(
|
|
2836
|
+ email='test@test.test',
|
|
2837
|
+ password='pass',
|
|
2838
|
+ name='bob',
|
|
2839
|
+ groups=groups,
|
|
2840
|
+ timezone='Europe/Paris',
|
|
2841
|
+ do_save=True,
|
|
2842
|
+ do_notify=False,
|
|
2843
|
+ )
|
|
2844
|
+ test_user2 = uapi.create_user(
|
|
2845
|
+ email='test2@test2.test2',
|
|
2846
|
+ password='pass',
|
|
2847
|
+ name='bob2',
|
|
2848
|
+ groups=groups,
|
|
2849
|
+ timezone='Europe/Paris',
|
|
2850
|
+ do_save=True,
|
|
2851
|
+ do_notify=False,
|
|
2852
|
+ )
|
|
2853
|
+ uapi.save(test_user)
|
|
2854
|
+ uapi.save(test_user2)
|
|
2855
|
+ transaction.commit()
|
|
2856
|
+ user_id = int(admin.user_id)
|
|
2857
|
+
|
|
2858
|
+ self.testapp.authorization = (
|
|
2859
|
+ 'Basic',
|
|
2860
|
+ (
|
|
2861
|
+ 'admin@admin.admin',
|
|
2862
|
+ 'admin@admin.admin'
|
|
2863
|
+ )
|
|
2864
|
+ )
|
|
2865
|
+ params = {
|
|
2866
|
+ 'acp': 'test',
|
|
2867
|
+ }
|
|
2868
|
+ res = self.testapp.get(
|
|
2869
|
+ '/api/v2/users/{user_id}/known_members'.format(user_id=user_id),
|
|
2870
|
+ status=200,
|
|
2871
|
+ params=params,
|
|
2872
|
+ )
|
|
2873
|
+ res = res.json_body
|
|
2874
|
+ assert len(res) == 2
|
|
2875
|
+ assert res[0]['user_id'] == test_user.user_id
|
|
2876
|
+ assert res[0]['public_name'] == test_user.display_name
|
|
2877
|
+ assert res[0]['avatar_url'] is None
|
|
2878
|
+
|
|
2879
|
+ assert res[1]['user_id'] == test_user2.user_id
|
|
2880
|
+ assert res[1]['public_name'] == test_user2.display_name
|
|
2881
|
+ assert res[1]['avatar_url'] is None
|
|
2882
|
+
|
|
2883
|
+ def test_api__get_user__err_403__admin__too_small_acp(self):
|
|
2884
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
2885
|
+ admin = dbsession.query(models.User) \
|
|
2886
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
2887
|
+ .one()
|
|
2888
|
+ uapi = UserApi(
|
|
2889
|
+ current_user=admin,
|
|
2890
|
+ session=dbsession,
|
|
2891
|
+ config=self.app_config,
|
|
2892
|
+ )
|
|
2893
|
+ gapi = GroupApi(
|
|
2894
|
+ current_user=admin,
|
|
2895
|
+ session=dbsession,
|
|
2896
|
+ config=self.app_config,
|
|
2897
|
+ )
|
|
2898
|
+ groups = [gapi.get_one_with_name('users')]
|
|
2899
|
+ test_user = uapi.create_user(
|
|
2900
|
+ email='test@test.test',
|
|
2901
|
+ password='pass',
|
|
2902
|
+ name='bob',
|
|
2903
|
+ groups=groups,
|
|
2904
|
+ timezone='Europe/Paris',
|
|
2905
|
+ do_save=True,
|
|
2906
|
+ do_notify=False,
|
|
2907
|
+ )
|
|
2908
|
+ test_user2 = uapi.create_user(
|
|
2909
|
+ email='test2@test2.test2',
|
|
2910
|
+ password='pass',
|
|
2911
|
+ name='bob2',
|
|
2912
|
+ groups=groups,
|
|
2913
|
+ timezone='Europe/Paris',
|
|
2914
|
+ do_save=True,
|
|
2915
|
+ do_notify=False,
|
|
2916
|
+ )
|
|
2917
|
+ uapi.save(test_user)
|
|
2918
|
+ transaction.commit()
|
|
2919
|
+ user_id = int(admin.user_id)
|
|
2920
|
+
|
|
2921
|
+ self.testapp.authorization = (
|
|
2922
|
+ 'Basic',
|
|
2923
|
+ (
|
|
2924
|
+ 'admin@admin.admin',
|
|
2925
|
+ 'admin@admin.admin'
|
|
2926
|
+ )
|
|
2927
|
+ )
|
|
2928
|
+ params = {
|
|
2929
|
+ 'acp': 't',
|
|
2930
|
+ }
|
|
2931
|
+ res = self.testapp.get(
|
|
2932
|
+ '/api/v2/users/{user_id}/known_members'.format(user_id=user_id),
|
|
2933
|
+ status=400,
|
|
2934
|
+ params=params
|
|
2935
|
+ )
|
|
2936
|
+
|
|
2937
|
+ def test_api__get_user__ok_200__normal_user_by_email(self):
|
|
2938
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
2939
|
+ admin = dbsession.query(models.User) \
|
|
2940
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
2941
|
+ .one()
|
|
2942
|
+ uapi = UserApi(
|
|
2943
|
+ current_user=admin,
|
|
2944
|
+ session=dbsession,
|
|
2945
|
+ config=self.app_config,
|
|
2946
|
+ )
|
|
2947
|
+ gapi = GroupApi(
|
|
2948
|
+ current_user=admin,
|
|
2949
|
+ session=dbsession,
|
|
2950
|
+ config=self.app_config,
|
|
2951
|
+ )
|
|
2952
|
+ groups = [gapi.get_one_with_name('users')]
|
|
2953
|
+ test_user = uapi.create_user(
|
|
2954
|
+ email='test@test.test',
|
|
2955
|
+ password='pass',
|
|
2956
|
+ name='bob',
|
|
2957
|
+ groups=groups,
|
|
2958
|
+ timezone='Europe/Paris',
|
|
2959
|
+ do_save=True,
|
|
2960
|
+ do_notify=False,
|
|
2961
|
+ )
|
|
2962
|
+ test_user2 = uapi.create_user(
|
|
2963
|
+ email='test2@test2.test2',
|
|
2964
|
+ password='pass',
|
|
2965
|
+ name='bob2',
|
|
2966
|
+ groups=groups,
|
|
2967
|
+ timezone='Europe/Paris',
|
|
2968
|
+ do_save=True,
|
|
2969
|
+ do_notify=False,
|
|
2970
|
+ )
|
|
2971
|
+ test_user3 = uapi.create_user(
|
|
2972
|
+ email='test3@test3.test3',
|
|
2973
|
+ password='pass',
|
|
2974
|
+ name='bob3',
|
|
2975
|
+ groups=groups,
|
|
2976
|
+ timezone='Europe/Paris',
|
|
2977
|
+ do_save=True,
|
|
2978
|
+ do_notify=False,
|
|
2979
|
+ )
|
|
2980
|
+ uapi.save(test_user)
|
|
2981
|
+ uapi.save(test_user2)
|
|
2982
|
+ uapi.save(test_user3)
|
|
2983
|
+ workspace_api = WorkspaceApi(
|
|
2984
|
+ current_user=admin,
|
|
2985
|
+ session=dbsession,
|
|
2986
|
+ config=self.app_config
|
|
2987
|
+
|
|
2988
|
+ )
|
|
2989
|
+ workspace = WorkspaceApi(
|
|
2990
|
+ current_user=admin,
|
|
2991
|
+ session=dbsession,
|
|
2992
|
+ config=self.app_config,
|
|
2993
|
+ ).create_workspace(
|
|
2994
|
+ 'test workspace',
|
|
2995
|
+ save_now=True
|
|
2996
|
+ )
|
|
2997
|
+ role_api = RoleApi(
|
|
2998
|
+ current_user=admin,
|
|
2999
|
+ session=dbsession,
|
|
3000
|
+ config=self.app_config,
|
|
3001
|
+ )
|
|
3002
|
+ role_api.create_one(test_user, workspace, UserRoleInWorkspace.READER, False)
|
|
3003
|
+ role_api.create_one(test_user2, workspace, UserRoleInWorkspace.READER, False)
|
|
3004
|
+ transaction.commit()
|
|
3005
|
+ user_id = int(test_user.user_id)
|
|
3006
|
+
|
|
3007
|
+ self.testapp.authorization = (
|
|
3008
|
+ 'Basic',
|
|
3009
|
+ (
|
|
3010
|
+ 'test@test.test',
|
|
3011
|
+ 'pass'
|
|
3012
|
+ )
|
|
3013
|
+ )
|
|
3014
|
+ params = {
|
|
3015
|
+ 'acp': 'test',
|
|
3016
|
+ }
|
|
3017
|
+ res = self.testapp.get(
|
|
3018
|
+ '/api/v2/users/{user_id}/known_members'.format(user_id=user_id),
|
|
3019
|
+ status=200,
|
|
3020
|
+ params=params
|
|
3021
|
+ )
|
|
3022
|
+ res = res.json_body
|
|
3023
|
+ assert len(res) == 2
|
|
3024
|
+ assert res[0]['user_id'] == test_user.user_id
|
|
3025
|
+ assert res[0]['public_name'] == test_user.display_name
|
|
3026
|
+ assert res[0]['avatar_url'] is None
|
|
3027
|
+
|
|
3028
|
+ assert res[1]['user_id'] == test_user2.user_id
|
|
3029
|
+ assert res[1]['public_name'] == test_user2.display_name
|
|
3030
|
+ assert res[1]['avatar_url'] is None
|
|
3031
|
+
|
|
3032
|
+
|
2649
|
3033
|
class TestSetEmailEndpoint(FunctionalTest):
|
2650
|
3034
|
# -*- coding: utf-8 -*-
|
2651
|
3035
|
"""
|
|
@@ -3025,6 +3409,12 @@ class TestSetPasswordEndpoint(FunctionalTest):
|
3025
|
3409
|
status=204,
|
3026
|
3410
|
)
|
3027
|
3411
|
# Check After
|
|
3412
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
3413
|
+ uapi = UserApi(
|
|
3414
|
+ current_user=admin,
|
|
3415
|
+ session=dbsession,
|
|
3416
|
+ config=self.app_config,
|
|
3417
|
+ )
|
3028
|
3418
|
user = uapi.get_one(user_id)
|
3029
|
3419
|
assert not user.validate_password('pass')
|
3030
|
3420
|
assert user.validate_password('mynewpassword')
|
|
@@ -3080,6 +3470,12 @@ class TestSetPasswordEndpoint(FunctionalTest):
|
3080
|
3470
|
params=params,
|
3081
|
3471
|
status=403,
|
3082
|
3472
|
)
|
|
3473
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
3474
|
+ uapi = UserApi(
|
|
3475
|
+ current_user=admin,
|
|
3476
|
+ session=dbsession,
|
|
3477
|
+ config=self.app_config,
|
|
3478
|
+ )
|
3083
|
3479
|
# Check After
|
3084
|
3480
|
user = uapi.get_one(user_id)
|
3085
|
3481
|
assert user.validate_password('pass')
|
|
@@ -3138,6 +3534,12 @@ class TestSetPasswordEndpoint(FunctionalTest):
|
3138
|
3534
|
status=400,
|
3139
|
3535
|
)
|
3140
|
3536
|
# Check After
|
|
3537
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
3538
|
+ uapi = UserApi(
|
|
3539
|
+ current_user=admin,
|
|
3540
|
+ session=dbsession,
|
|
3541
|
+ config=self.app_config,
|
|
3542
|
+ )
|
3141
|
3543
|
user = uapi.get_one(user_id)
|
3142
|
3544
|
assert user.validate_password('pass')
|
3143
|
3545
|
assert not user.validate_password('mynewpassword')
|
|
@@ -3195,6 +3597,12 @@ class TestSetPasswordEndpoint(FunctionalTest):
|
3195
|
3597
|
status=204,
|
3196
|
3598
|
)
|
3197
|
3599
|
# Check After
|
|
3600
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
3601
|
+ uapi = UserApi(
|
|
3602
|
+ current_user=admin,
|
|
3603
|
+ session=dbsession,
|
|
3604
|
+ config=self.app_config,
|
|
3605
|
+ )
|
3198
|
3606
|
user = uapi.get_one(user_id)
|
3199
|
3607
|
assert not user.validate_password('pass')
|
3200
|
3608
|
assert user.validate_password('mynewpassword')
|