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

DoclerLabs / api-client-generator / 9254068657

27 May 2024 11:30AM UTC coverage: 86.981% (-1.4%) from 88.428%
9254068657

push

github

web-flow
Merge pull request #112 from DoclerLabs/php81

php 8.1 features

106 of 172 new or added lines in 20 files covered. (61.63%)

4 existing lines in 2 files now uncovered.

2913 of 3349 relevant lines covered (86.98%)

4.92 hits per line

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

29.69
/src/Generator/Security/XWSSESecurityStrategy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace DoclerLabs\ApiClientGenerator\Generator\Security;
6

7
use cebe\openapi\spec\SecurityScheme;
8
use DoclerLabs\ApiClientGenerator\Entity\Operation;
9
use DoclerLabs\ApiClientGenerator\Input\Specification;
10

11
class XWSSESecurityStrategy extends ApiKeyInHeaderSecurityStrategy
12
{
13
    public const HEADER_NAME = 'X-WSSE';
14

15
    private const PROPERTY_USERNAME = 'xwsseUsername';
16

17
    private const PROPERTY_SECRET = 'xwsseSecret';
18

19
    public function getProperties(Operation $operation, Specification $specification): array
20
    {
21
        if ($this->phpVersion->isConstructorPropertyPromotionSupported()) {
1✔
22
            return [];
×
23
        }
24

25
        $statements = [];
1✔
26

27
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
28
            $statements[] = $this->builder->localProperty(
×
29
                self::PROPERTY_USERNAME,
×
30
                'string',
×
NEW
31
                'string',
×
NEW
32
                readonly: true
×
33
            );
34
            $statements[] = $this->builder->localProperty(
×
35
                self::PROPERTY_SECRET,
×
36
                'string',
×
NEW
37
                'string',
×
NEW
38
                readonly: true
×
39
            );
40
        }
41

42
        return $statements;
1✔
43
    }
44

45
    public function getConstructorParams(Operation $operation, Specification $specification): array
46
    {
47
        $params = [];
1✔
48

49
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
50
            $params[] = $this->builder
×
51
                ->param(self::PROPERTY_USERNAME)
×
52
                ->setType('string');
×
53
            $params[] = $this->builder
×
54
                ->param(self::PROPERTY_SECRET)
×
55
                ->setType('string');
×
56
        }
57

58
        return $params;
1✔
59
    }
60

61
    public function getConstructorParamInits(Operation $operation, Specification $specification): array
62
    {
63
        if ($this->phpVersion->isConstructorPropertyPromotionSupported()) {
1✔
64
            return [];
×
65
        }
66

67
        $paramInits = [];
1✔
68

69
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
70
            $paramInits[] = $this->builder->assign(
×
71
                $this->builder->localPropertyFetch(self::PROPERTY_USERNAME),
×
72
                $this->builder->var(self::PROPERTY_USERNAME)
×
73
            );
74
            $paramInits[] = $this->builder->assign(
×
75
                $this->builder->localPropertyFetch(self::PROPERTY_SECRET),
×
76
                $this->builder->var(self::PROPERTY_SECRET)
×
77
            );
78
        }
79

80
        return $paramInits;
1✔
81
    }
82

83
    public function getSecurityHeadersStmts(Operation $operation, Specification $specification): array
84
    {
85
        $stmts = [];
1✔
86

87
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
88
            $nonce       = $this->builder->var('nonce');
×
89
            $nonceAssign = $this->builder->assign(
×
90
                $nonce,
91
                $this->builder->funcCall('bin2hex', [$this->builder->funcCall('random_bytes', [16])])
×
92
            );
93

94
            $timestamp       = $this->builder->var('timestamp');
×
95
            $timestampAssign = $this->builder->assign($timestamp, $this->builder->funcCall('gmdate', ['c']));
×
96

97
            $xwsse       = $this->builder->var('xwsse');
×
98
            $xwsseAssign = $this->builder->assign(
×
99
                $xwsse,
100
                $this->builder->funcCall(
×
101
                    'sprintf',
×
102
                    [
103
                        'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
×
104
                        $this->builder->localPropertyFetch(self::PROPERTY_USERNAME),
×
105
                        $this->builder->funcCall(
×
106
                            'base64_encode',
×
107
                            [
108
                                $this->builder->funcCall(
×
109
                                    'sha1',
×
110
                                    [
111
                                        $this->builder->concat(
×
112
                                            $nonce,
113
                                            $timestamp,
114
                                            $this->builder->localPropertyFetch(self::PROPERTY_SECRET),
×
115
                                        ),
116
                                    ]
117
                                ),
118
                            ]
119
                        ),
120
                        $nonce,
×
121
                        $timestamp,
×
122
                    ]
123
                )
124
            );
125

126
            array_push($stmts, $nonceAssign, $timestampAssign, $xwsseAssign);
×
127
        }
128

129
        return $stmts;
1✔
130
    }
131

132
    public function getSecurityHeaders(Operation $operation, Specification $specification): array
133
    {
134
        $headers = [];
1✔
135

136
        if ($this->isAuthenticationAvailable($operation, $specification)) {
1✔
137
            $headers[self::HEADER_NAME] = $this->builder->var('xwsse');
×
138
        }
139

140
        return $headers;
1✔
141
    }
142

143
    protected function matches(SecurityScheme $securityScheme): bool
144
    {
145
        return parent::matches($securityScheme)
1✔
146
            && $securityScheme->name === self::HEADER_NAME;
1✔
147
    }
148
}
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

© 2025 Coveralls, Inc