Authstack SAML Service Provider : code coverage of AuthStack\SAMLServiceProvider\Model\ServiceProvider

# Code coverage of Authstack SAML Service Provider: AuthStack\SAMLServiceProvider\Model\ServiceProvider

## Class code coverage 93.48%

### Methods

- 100% getEntityId
- 100% getIdPEntityId
- 100% getBaseUrl
- 100% getNameIdFormat
- 100% wantsSignedMessages
- 100% wantsSignedAssertions
- 100% wantsEncryptedAssertions
- 100% getACSPath
- 100% getACSUrl
- 100% getACSBinding
- 100% getLogoutServicePath
- 100% getLogoutServiceUrl
- 100% getLogoutServiceBinding
- 100% validateSignature
- 0% validateStatus
- 100% validateIssuer
- 100% validateDestination
- 100% validateLifetime
- 100% getUpperDT
- 100% getLowerDT
- 100% getValidationUpperTimeBoundary
- 100% getValidationLowerTimeBoundary
- 100% getSigningKey
- 100% getSignatureWriter
- 0% getSigningPublicKey
- 100% getSigningKeyX509Cert
- 100% getSigningPrivateKey
- 100% getSigningPrivateKeyPassphrase
- 100% getSigningDigestAlgorithm
- 100% getDecryptionKey
- 100% getDecrypter
- 100% getDecryptionKeyPrivateKey
- 100% getDecryptionKeyPassphrase
- 100% getDecryptionKeyAlgorithm

### Source

Line | Code
--- | ---
1 |
    <?php
2 |
3 |
    namespace AuthStack\SAMLServiceProvider\Model;
4 |
5 |
    use LightSaml\Credential\KeyHelper;
6 |
    use LightSaml\Credential\X509Certificate;
7 |
    use LightSaml\Model\XmlDSig\SignatureWriter;
8 |
    use RobRichards\XMLSecLibs\XMLSecurityKey;
9 |
10 |
    class ServiceProvider
11 |
    {
12 |
        /**
13 |
         * @return null|string
14 |
         */
15 |
        public function getEntityId(): ?string
16 |
        {
17 |
            return config('saml.sp.EntityId');
18 |
        }
19 |
20 |
        /**
21 |
         * @return string
22 |
         */
23 |
        public function getIdPEntityId(): string
24 |
        {
25 |
            return config('saml.sp.IdentityProvider');
26 |
        }
27 |
28 |
        /**
29 |
         * @return string
30 |
         */
31 |
        public function getBaseUrl(): string
32 |
        {
33 |
            return config('saml.sp.baseUrl');
34 |
        }
35 |
36 |
        /**
37 |
         * @return null|string
38 |
         */
39 |
        public function getNameIdFormat(): ?string
40 |
        {
41 |
            return config('saml.sp.nameIdFormat');
42 |
        }
43 |
44 |
        /**
45 |
         * @return bool
46 |
         */
47 |
        public function wantsSignedMessages(): bool
48 |
        {
49 |
            return config('saml.sp.wantsSignedMessages');
50 |
        }
51 |
52 |
        /**
53 |
         * @return bool
54 |
         */
55 |
        public function wantsSignedAssertions(): bool
56 |
        {
57 |
            return config('saml.sp.wantsSignedAssertions');
58 |
        }
59 |
60 |
        /**
61 |
         * @return bool
62 |
         */
63 |
        public function wantsEncryptedAssertions(): bool
64 |
        {
65 |
            return config('saml.sp.wantsEncryptedAssertions');
66 |
        }
67 |
68 |
        /**
69 |
         * @return string
70 |
         */
71 |
        public function getACSPath(): string
72 |
        {
73 |
            return config('saml.sp.AssertionConsumerService.location');
74 |
        }
75 |
76 |
        /**
77 |
         * @return string
78 |
         */
79 |
        public function getACSUrl(): string
80 |
        {
81 |
            return sprintf("%s%s", $this->getBaseUrl(), $this->getACSPath());
82 |
        }
83 |
84 |
        /**
85 |
         * @return string
86 |
         */
87 |
        public function getACSBinding(): string
88 |
        {
89 |
            return config('saml.sp.AssertionConsumerService.binding');
90 |
        }
91 |
92 |
        /**
93 |
         * @return string
94 |
         */
95 |
        public function getLogoutServicePath(): string
96 |
        {
97 |
            return config('saml.sp.SLO.location');
98 |
        }
99 |
100 |
        /**
101 |
         * @return string
102 |
         */
103 |
        public function getLogoutServiceUrl(): string
104 |
        {
105 |
            return sprintf("%s%s", $this->getBaseUrl(), $this->getLogoutServicePath());
106 |
        }
107 |
108 |
        /**
109 |
         * @return string
110 |
         */
111 |
        public function getLogoutServiceBinding(): string
112 |
        {
113 |
            return config('saml.sp.SLO.binding');
114 |
        }
115 |
116 |
        public function validateSignature(): bool
117 |
        {
118 |
            return config('saml.sp.validate.signature');
119 |
        }
120 |
121 |
        /**
122 |
         * @return bool
123 |
         */
124 |
        public function validateStatus(): bool
125 |
        {
126 |
            return config('saml.sp.validate.status');
127 |
        }
128 |
129 |
        /**
130 |
         * @return bool
131 |
         */
132 |
        public function validateIssuer(): bool
133 |
        {
134 |
            return config('saml.sp.validate.issuer');
135 |
        }
136 |
137 |
        /**
138 |
         * @return bool
139 |
         */
140 |
        public function validateDestination(): bool
141 |
        {
142 |
            return config('saml.sp.validate.destination');
143 |
        }
144 |
145 |
        /**
146 |
         * @return bool
147 |
         */
148 |
        public function validateLifetime(): bool
149 |
        {
150 |
            return config('saml.sp.validate.lifetime');
151 |
        }
152 |
153 |
        /**
154 |
         * @return \DateTime
155 |
         */
156 |
        public function getUpperDT(): \DateTime
157 |
        {
158 |
            return new \DateTime($this->getValidationUpperTimeBoundary(), new \DateTimeZone('UTC'));
159 |
        }
160 |
161 |
        /**
162 |
         * @return \DateTime
163 |
         */
164 |
        public function getLowerDT(): \DateTime
165 |
        {
166 |
            return new \DateTime($this->getValidationLowerTimeBoundary(), new \DateTimeZone('UTC'));
167 |
        }
168 |
169 |
        /**
170 |
         * @return string
171 |
         */
172 |
        public function getValidationUpperTimeBoundary(): string
173 |
        {
174 |
            return config('saml.sp.validate.upper');
175 |
        }
176 |
177 |
        /**
178 |
         * @return string
179 |
         */
180 |
        public function getValidationLowerTimeBoundary(): string
181 |
        {
182 |
            return config('saml.sp.validate.lower');
183 |
        }
184 |
185 |
        /**
186 |
         * @return array
187 |
         */
188 |
        public function getSigningKey(): array
189 |
        {
190 |
            return config('saml.sp.keys.signing', []);
191 |
        }
192 |
193 |
        /**
194 |
         * @return SignatureWriter
195 |
         */
196 |
        public function getSignatureWriter(): SignatureWriter
197 |
        {
198 |
            $x509 = new X509Certificate();
199 |
200 |
            $x509->setData($this->getSigningKeyX509Cert());
201 |
202 |
            $priv = KeyHelper::createPrivateKey(
203 |
                $this->getSigningPrivateKey(),
204 |
                $this->getSigningPrivateKeyPassphrase(),
205 |
                false,
206 |
                $this->getSigningDigestAlgorithm()
207 |
            );
208 |
209 |
            return new SignatureWriter($x509, $priv);
210 |
        }
211 |
212 |
        /**
213 |
         * @return XMLSecurityKey
214 |
         */
215 |
        public function getSigningPublicKey(): XMLSecurityKey
216 |
        {
217 |
            return KeyHelper::createPublicKey(
218 |
                (new X509Certificate())->setData($this->getSigningKeyX509Cert())
219 |
            );
220 |
        }
221 |
222 |
        /**
223 |
         * @return string
224 |
         */
225 |
        public function getSigningKeyX509Cert(): string
226 |
        {
227 |
            return config('saml.sp.keys.signing.x509');
228 |
        }
229 |
230 |
        /**
231 |
         * @return string
232 |
         */
233 |
        public function getSigningPrivateKey(): string
234 |
        {
235 |
            return config('saml.sp.keys.signing.private');
236 |
        }
237 |
238 |
        /**
239 |
         * @return null|string
240 |
         */
241 |
        public function getSigningPrivateKeyPassphrase(): ?string
242 |
        {
243 |
            return config('saml.sp.keys.signing.passphrase');
244 |
        }
245 |
246 |
        /**
247 |
         * @return string
248 |
         */
249 |
        public function getSigningDigestAlgorithm(): string
250 |
        {
251 |
            return config('saml.sp.keys.signing.algorithm');
252 |
        }
253 |
254 |
        /**
255 |
         * @return array
256 |
         */
257 |
        public function getDecryptionKey(): array
258 |
        {
259 |
            return config('saml.sp.keys.encryption', []);
260 |
        }
261 |
262 |
        /**
263 |
         * @return XMLSecurityKey
264 |
         */
265 |
        public function getDecrypter(): XMLSecurityKey
266 |
        {
267 |
            return KeyHelper::createPrivateKey(
268 |
                $this->getDecryptionKeyPrivateKey(),
269 |
                $this->getDecryptionKeyPassphrase(),
270 |
                false,
271 |
                $this->getDecryptionKeyAlgorithm()
272 |
            );
273 |
        }
274 |
275 |
        /**
276 |
         * @return null|string
277 |
         */
278 |
        public function getDecryptionKeyPrivateKey(): ?string
279 |
        {
280 |
            return config('saml.sp.keys.encryption.private');
281 |
        }
282 |
283 |
        /**
284 |
         * @return null|string
285 |
         */
286 |
        public function getDecryptionKeyPassphrase(): ?string
287 |
        {
288 |
            return config('saml.sp.keys.encryption.passphrase');
289 |
        }
290 |
291 |
        /**
292 |
         * @return null|string
293 |
         */
294 |
        public function getDecryptionKeyAlgorithm(): ?string
295 |
        {
296 |
            return config('saml.sp.keys.encryption.algorithm');
297 |
        }
298 |
    }