-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from ember-nexus/github-issue/131
Add `/.well-known/security.txt` endpoint, documentation for it and (d…
- Loading branch information
Showing
17 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# <span class="method-get">GET</span>` /.well-known/security.txt -` Get Well Known security.txt | ||
|
||
<!-- panels:start --> | ||
<!-- div:left-panel --> | ||
|
||
Returns the configured security.txt file. | ||
|
||
See [https://securitytxt.org/](https://securitytxt.org/) for details regarding this file standard. | ||
|
||
## Request Example | ||
|
||
```bash | ||
curl https://api.localhost/.well-known/security.txt | ||
``` | ||
|
||
<!-- tabs:start --> | ||
|
||
### **🟢 Success 200** | ||
|
||
<div class="code-title auto-refresh">Response Headers</div> | ||
|
||
[Response Body](./get-well-known-security-txt/200-response-header.txt ':include :type=code') | ||
|
||
<div class="code-title auto-refresh">Response Body</div> | ||
|
||
[Response Body](./get-well-known-security-txt/200-response-body.txt ':include :type=code') | ||
|
||
<!-- tabs:end --> | ||
|
||
<!-- div:right-panel --> | ||
|
||
## Internal Workflow | ||
|
||
The server returns the configured file directly. | ||
|
||
<div id="graph-container-1" class="graph-container" style="height:800px"></div> | ||
|
||
<!-- panels:end --> | ||
|
||
<script> | ||
G6.registerEdge('polyline-edge', { | ||
draw(cfg, group) { | ||
const { startPoint, endPoint } = cfg; | ||
const hgap = Math.abs(endPoint.x - startPoint.x); | ||
|
||
const path = [ | ||
['M', startPoint.x, startPoint.y], | ||
[ | ||
'C', | ||
startPoint.x + hgap / 4, | ||
startPoint.y, | ||
endPoint.x - hgap / 2, | ||
endPoint.y, | ||
endPoint.x, | ||
endPoint.y, | ||
], | ||
]; | ||
const shape = group.addShape('path', { | ||
attrs: { | ||
stroke: '#AAB7C4', | ||
path, | ||
}, | ||
name: 'path-shape', | ||
}); | ||
const midPoint = { | ||
x: (startPoint.x + endPoint.x) / 2, | ||
y: (startPoint.y + endPoint.y) / 2, | ||
}; | ||
const label = group.addShape('text', { | ||
attrs: { | ||
text: cfg.label + '###########', | ||
x: midPoint.x, | ||
y: midPoint.y, | ||
textAlign: 'center', | ||
textBaseline: 'middle', | ||
fill: '#000', | ||
fontSize: 14, | ||
}, | ||
name: 'label-shape', | ||
}); | ||
return shape; | ||
}, | ||
}); | ||
renderWorkflow(document.getElementById('graph-container-1'), { | ||
nodes: [ | ||
{ id: 'init', ...workflowStart, label: 'server receives GET-request' }, | ||
{ id: 'success200', ...workflowEndSuccess , label: "return 200"}, | ||
], | ||
edges: [ | ||
{ source: 'init', target: 'success200', label: '' }, | ||
], | ||
}, 'TB'); | ||
</script> |
2 changes: 2 additions & 0 deletions
2
docs/api-endpoints/system/get-well-known-security-txt/200-response-body.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Contact: https://ember-nexus.dev/contact | ||
Expires: 2026-01-01T00:00:00.000Z |
10 changes: 10 additions & 0 deletions
10
docs/api-endpoints/system/get-well-known-security-txt/200-response-header.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Access-Control-Allow-Headers: Authorization, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method | ||
Access-Control-Allow-Methods: GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK | ||
Access-Control-Allow-Origin: * | ||
Allow: GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK | ||
Cache-Control: no-cache, private | ||
Content-Type: text/plain; charset=utf-8 | ||
Date: Fri, 22 Dec 2023 23:05:08 GMT | ||
Server: Unit | ||
Transfer-Encoding: chunked | ||
X-Powered-By: Ember-Nexus-API |
34 changes: 34 additions & 0 deletions
34
src/Controller/System/GetWellKnownSecurityTxtController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Controller\System; | ||
|
||
use App\Factory\Exception\Client404NotFoundExceptionFactory; | ||
use App\Response\TextResponse; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class GetWellKnownSecurityTxtController extends AbstractController | ||
{ | ||
public const string PATH_TO_WELL_KNOWN_SECURITY_TXT = '/well-known-security.txt'; | ||
|
||
public function __construct( | ||
private Client404NotFoundExceptionFactory $client404NotFoundExceptionFactory | ||
) { | ||
} | ||
|
||
#[Route( | ||
'/.well-known/security.txt', | ||
name: 'get-well-known-security-txt', | ||
methods: ['GET'] | ||
)] | ||
public function getWellKnownSecurityTxt(): Response | ||
{ | ||
if (!file_exists(self::PATH_TO_WELL_KNOWN_SECURITY_TXT)) { | ||
throw $this->client404NotFoundExceptionFactory->createFromTemplate(); | ||
} | ||
$wellKnownSecurityTxtContent = \Safe\file_get_contents(self::PATH_TO_WELL_KNOWN_SECURITY_TXT); | ||
|
||
return new TextResponse($wellKnownSecurityTxtContent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Contact: https://ember-nexus.dev/contact | ||
Expires: 2026-01-01T00:00:00.000Z |
31 changes: 31 additions & 0 deletions
31
tests/ExampleGenerationController/System/GetWellKnownSecurityTxtTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\tests\ExampleGenerationController\System; | ||
|
||
use App\Tests\ExampleGenerationController\BaseRequestTestCase; | ||
|
||
class GetWellKnownSecurityTxtTest extends BaseRequestTestCase | ||
{ | ||
private const string PATH_TO_ROOT = __DIR__.'/../../../'; | ||
|
||
public function testGetWellKnownSecurityTxtSuccess(): void | ||
{ | ||
$response = $this->runGetRequest('/.well-known/security.txt', null); | ||
$documentationHeadersPath = 'docs/api-endpoints/system/get-well-known-security-txt/200-response-header.txt'; | ||
$documentationBodyPath = 'docs/api-endpoints/system/get-well-known-security-txt/200-response-body.txt'; | ||
$this->assertHeadersInDocumentationAreIdenticalToHeadersFromRequest( | ||
self::PATH_TO_ROOT, | ||
$documentationHeadersPath, | ||
$response | ||
); | ||
$this->assertBodyInDocumentationIsIdenticalToBodyFromRequest( | ||
self::PATH_TO_ROOT, | ||
$documentationBodyPath, | ||
$response, | ||
false, | ||
[ | ||
'Expires', | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Contact: https://ember-nexus.dev/contact | ||
Expires: 2026-01-01T00:00:00.000Z |
14 changes: 14 additions & 0 deletions
14
tests/FeatureTests/Endpoint/System/GetWellKnownSecurityTxtTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\tests\FeatureTests\Endpoint\System; | ||
|
||
use App\Tests\FeatureTests\BaseRequestTestCase; | ||
|
||
class GetWellKnownSecurityTxtTest extends BaseRequestTestCase | ||
{ | ||
public function testGetWellKnownSecurityTxt(): void | ||
{ | ||
$response = $this->runGetRequest('/.well-known/security.txt', null); | ||
$this->assertIsTextResponse($response, 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Contact: https://ember-nexus.dev/contact | ||
Expires: 2026-01-01T00:00:00.000Z |