Browse Source

Do not test PAM authentication by default (#9027)

* Do not test PAM authentication by default

* Disable PAM tests if PAM is not enabled
Eugen Rochko 2 months ago
parent
commit
d5bfba3262
No account linked to committer's email address
2 changed files with 38 additions and 40 deletions
  1. 0
    4
      .env.test
  2. 38
    36
      spec/controllers/auth/sessions_controller_spec.rb

+ 0
- 4
.env.test View File

@@ -3,7 +3,3 @@ NODE_ENV=test
3 3
 # Federation
4 4
 LOCAL_DOMAIN=cb6e6126.ngrok.io
5 5
 LOCAL_HTTPS=true
6
-# test pam authentication
7
-PAM_ENABLED=true
8
-PAM_DEFAULT_SERVICE=pam_test
9
-PAM_CONTROLLED_SERVICE=pam_test_controlled

+ 38
- 36
spec/controllers/auth/sessions_controller_spec.rb View File

@@ -55,53 +55,55 @@ RSpec.describe Auth::SessionsController, type: :controller do
55 55
       request.env['devise.mapping'] = Devise.mappings[:user]
56 56
     end
57 57
 
58
-    context 'using PAM authentication' do
59
-      context 'using a valid password' do
60
-        before do
61
-          post :create, params: { user: { email: "pam_user1", password: '123456' } }
62
-        end
58
+    if ENV['PAM_ENABLED'] == 'true'
59
+      context 'using PAM authentication' do
60
+        context 'using a valid password' do
61
+          before do
62
+            post :create, params: { user: { email: "pam_user1", password: '123456' } }
63
+          end
63 64
 
64
-        it 'redirects to home' do
65
-          expect(response).to redirect_to(root_path)
66
-        end
65
+          it 'redirects to home' do
66
+            expect(response).to redirect_to(root_path)
67
+          end
67 68
 
68
-        it 'logs the user in' do
69
-          expect(controller.current_user).to be_instance_of(User)
69
+          it 'logs the user in' do
70
+            expect(controller.current_user).to be_instance_of(User)
71
+          end
70 72
         end
71
-      end
72 73
 
73
-      context 'using an invalid password' do
74
-        before do
75
-          post :create, params: { user: { email: "pam_user1", password: 'WRONGPW' } }
76
-        end
74
+        context 'using an invalid password' do
75
+          before do
76
+            post :create, params: { user: { email: "pam_user1", password: 'WRONGPW' } }
77
+          end
77 78
 
78
-        it 'shows a login error' do
79
-          expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: 'Email')
80
-        end
79
+          it 'shows a login error' do
80
+            expect(flash[:alert]).to match I18n.t('devise.failure.invalid', authentication_keys: 'Email')
81
+          end
81 82
 
82
-        it "doesn't log the user in" do
83
-          expect(controller.current_user).to be_nil
83
+          it "doesn't log the user in" do
84
+            expect(controller.current_user).to be_nil
85
+          end
84 86
         end
85
-      end
86 87
 
87
-      context 'using a valid email and existing user' do
88
-        let(:user) do
89
-          account = Fabricate.build(:account, username: 'pam_user1')
90
-          account.save!(validate: false)
91
-          user = Fabricate(:user, email: 'pam@example.com', password: nil, account: account)
92
-          user
93
-        end
88
+        context 'using a valid email and existing user' do
89
+          let(:user) do
90
+            account = Fabricate.build(:account, username: 'pam_user1')
91
+            account.save!(validate: false)
92
+            user = Fabricate(:user, email: 'pam@example.com', password: nil, account: account)
93
+            user
94
+          end
94 95
 
95
-        before do
96
-          post :create, params: { user: { email: user.email, password: '123456' } }
97
-        end
96
+          before do
97
+            post :create, params: { user: { email: user.email, password: '123456' } }
98
+          end
98 99
 
99
-        it 'redirects to home' do
100
-          expect(response).to redirect_to(root_path)
101
-        end
100
+          it 'redirects to home' do
101
+            expect(response).to redirect_to(root_path)
102
+          end
102 103
 
103
-        it 'logs the user in' do
104
-          expect(controller.current_user).to eq user
104
+          it 'logs the user in' do
105
+            expect(controller.current_user).to eq user
106
+          end
105 107
         end
106 108
       end
107 109
     end