• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / auth / 16344800892

17 Jul 2025 12:13PM UTC coverage: 66.494% (+6.6%) from 59.854%
16344800892

push

github

daycry
Add comprehensive unit tests for helpers and services

This commit introduces extensive unit tests for helper functions (auth, checkEndpoint, checkIp, email), libraries (CheckIpInRange, Logger), and service classes (AttemptHandler, ExceptionHandler, RequestLogger). Also fixes ReflectionProperty usage in ExceptionHandler to correctly pass the exception object. These tests improve code coverage and ensure reliability of authentication, endpoint, IP checking, email, logging, and exception handling features.

1 of 1 new or added line in 1 file covered. (100.0%)

136 existing lines in 8 files now uncovered.

2177 of 3274 relevant lines covered (66.49%)

32.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.16
/src/Filters/ChainAuthFilter.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Auth\Filters;
15

16
use CodeIgniter\Filters\FilterInterface;
17
use CodeIgniter\HTTP\IncomingRequest;
18
use CodeIgniter\HTTP\RedirectResponse;
19
use CodeIgniter\HTTP\RequestInterface;
20
use CodeIgniter\HTTP\Response;
21
use CodeIgniter\HTTP\ResponseInterface;
22
use Daycry\Auth\Config\Auth;
23
use Exception;
24

25
/**
26
 * Chain Authentication Filter.
27
 *
28
 * Checks all authentication systems specified within
29
 * `Config\Auth->authenticationChain`
30
 */
31
class ChainAuthFilter implements FilterInterface
32
{
33
    /**
34
     * Do whatever processing this filter needs to do.
35
     * By default it should not return anything during
36
     * normal execution. However, when an abnormal state
37
     * is found, it should return an instance of
38
     * CodeIgniter\HTTP\Response. If it does, script
39
     * execution will end and that Response will be
40
     * sent back to the client, allowing for error pages,
41
     * redirects, etc.
42
     *
43
     * @param array|null $arguments
44
     *
45
     * @return RedirectResponse|void
46
     */
47
    public function before(RequestInterface $request, $arguments = null)
48
    {
49
        if (! $request instanceof IncomingRequest) {
3✔
50
            return;
×
51
        }
52

53
        helper('settings');
3✔
54

55
        /** @var Auth $config */
56
        $config = config(Auth::class);
3✔
57
        $chain  = $config->authenticationChain;
3✔
58

59
        foreach ($chain as $alias) {
3✔
60
            try {
61
                if (auth($alias)->loggedIn()) {
3✔
62
                    // Make sure Auth uses this Authenticator
63
                    auth()->setAuthenticator($alias);
2✔
64

65
                    return;
3✔
66
                }
67
            } catch (Exception $e) {
×
68
                continue;
×
69
            }
70
        }
71

72
        $acceptHeader = $request->getHeaderLine('Accept');
1✔
73
        if (str_contains($acceptHeader, 'application/json') || str_contains($acceptHeader, 'application/xml')) {
1✔
74
            return service('response')->setStatusCode(
×
75
                401,
×
76
                lang('Auth.invalidUser'),
×
UNCOV
77
            );
×
78
        }
79

80
        return redirect()->route('login');
1✔
81
    }
82

83
    /**
84
     * We don't have anything to do here.
85
     *
86
     * @param array|null $arguments
87
     */
88
    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null): void
89
    {
90
        // Nothing required
91
    }
2✔
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc