0
     ˆÏÎÍ553ÅÃÊ )    ‹      Å•[oÛ †ïû+»_NU×ÖöÔÅ‘-'%™ªiÚb£Ú`i–üúá8YÓ)Ñ:íteøüïóbCð*žôŸ¦}ô~1¢éÇwÃAáÀ}§/âúE—4[ ý1F8s®¼X¯×dÝ!Ú¤°˜AæŠ¼ÖÉáŽãè"¨jÑ
2A¹¢ÀI—‹h ¸øŠô�^9+¹ð3—«$—ìP ®V(¾”¹ \šd–0­K¿×Ì6¬Íê.¬¬›QSd�Ë$ÑÚº†FÒ\n©“ZµÈ•g öà]ÁÞV�h¾©Ü¶þ³3o`Mv«¦‰—¡G/MUˆ�.qÈ"EÖ°ƒdZYHrªH*—ÑÜ…øó 7ùâuà²jtP”±ñÛ^8¾�„1ŽÆ´ÐÓš‘×ÜáhH­C…ær)?+ž×â¹ÜžŸ0®5±°ÌÈ²"~’‚G<Fe:·%õ¬—ž 3ÇªZÂ–eÏÂ˜ÞÍúãE<˜Õ‘ðjŠ'wiŸq4õMåP,�`N›Íž¸^þµJly{è¢=�‘iæp„P�TþBL¥Ö
~…�ùdãþýœÄ"‘T‘të¿Žgýcç?Xm7Û�Fó²ÑºFÍë›v¡3Âyóáß2±ŒªTä:=;Q|9]÷,]‡\ý6ÝJ=(½V/BÓåf¿ò÷æŸØ¤6iŽÎc¼ð…ýéÀîT ¾¾¥ªñf    7   ˆl–äY>” ”¾R( 	Å ýÆCq±)‹Fÿ‘äÇò 8àFË`ÝmÉ?ŸÑƒh¹ÎÄË           998        1    82326     9324      540       46    42171    12501        0    18848    24611        0        0        0        0      264     2785
  
   !�236ÊÄË  ì    !<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>
  F   #ˆl–Ãa¾”ªi?u8 ¸Û71hß�þYÏ,ã�f1�­H¿üÿÒ„œxÏ_�uÐb&=LyZËcõÆÍ 1ˆ    ## Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe Auth do
  let(:password) { 'zammad' }
  let(:user)     { create(:user, password: password) }
  let(:instance) { described_class.new(user.login, password) }

  before do
    stub_const('Auth::BRUTE_FORCE_SLEEP', 0)
  end

  describe '.valid!' do
    context 'with an internal user' do
      context 'with valid credentials' do
        it 'check for valid credentials' do
          expect(instance.valid!).to be true
        end

        it 'check for not increased failed login count' do
          expect { instance.valid! }.not_to change { user.reload.login_failed }
        end

        context 'when not case-sensitive' do
          let(:instance) { described_class.new(user.login.upcase, password) }

          it 'returns true' do
            expect(instance.valid!).to be true
          end
        end

        context 'when email is used' do
          let(:instance) { described_class.new(user.email, password) }

          it 'check for valid credentials' do
            expect(instance.valid!).to be true
          end
        end

        context 'when previous login was' do
          context 'when never logged in' do
            it 'updates #last_login and #updated_at' do
              expect { instance.valid! }.to change { user.reload.last_login }.and change { user.reload.updated_at }
            end
          end

          context 'when less than 10 minutes ago' do
            before do
              instance.valid!
              travel 9.minutes
            end

            it 'does not update #last_login and #updated_at' do
              expect { instance.valid! }.to not_change { user.reload.last_login }.and not_change { user.reload.updated_at }
            end
          end

          context 'when more than 10 minutes ago' do
            before do
              instance.valid!
              travel 11.minutes
            end

            it 'updates #last_login and #updated_at' do
              expect { instance.valid! }.to change { user.reload.last_login }.and change { user.reload.updated_at }
            end
          end
        end
      end

      context 'with valid user and invalid password' do
        let(:instance) { described_class.new(user.login, 'wrong') }

        it 'raises an error and increases the failed login count' do
          expect { instance.valid! }.to raise_error(Auth::Error::AuthenticationFailed).and(change { user.reload.login_failed }.from(0).to(1))
        end

        it 'failed login avoids brute force attack' do
          allow(instance).to receive(:sleep)
          begin
            instance.try(:valid!)
          rescue Auth::Error::AuthenticationFailed
            # no-op
          end
          # sleep receives the stubbed value.
          expect(instance).to have_received(:sleep).with(0)
        end
      end

      context 'with