Skip to content

Commit 5339c9b

Browse files
authored
Fix AuthMiddleware path matching for subdirectory installations (#7968)
2 parents 0d26447 + 75bb122 commit 5339c9b

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/// <reference types="cypress" />
2+
3+
describe("API Public Registration", () => {
4+
it("Should allow family registration without authentication", () => {
5+
const testFamily = {
6+
Name: "Cypress Test Family",
7+
Address1: "123 Test Street",
8+
Address2: "",
9+
City: "Testville",
10+
State: "TS",
11+
Country: "US",
12+
Zip: "12345",
13+
HomePhone: "(555) 123-4567",
14+
Email: "test@example.com",
15+
people: [
16+
{
17+
firstName: "John",
18+
lastName: "Tester",
19+
gender: 1,
20+
role: 1,
21+
email: "john@example.com",
22+
cellPhone: "(555) 987-6543",
23+
homePhone: "",
24+
workPhone: "",
25+
birthday: "01/15/1980",
26+
hideAge: false
27+
}
28+
]
29+
};
30+
31+
cy.request({
32+
method: "POST",
33+
url: "/api/public/register/family",
34+
body: testFamily,
35+
}).then((resp) => {
36+
expect(resp.status).to.eq(200);
37+
expect(resp.body).to.have.property('Id');
38+
expect(resp.body.Name).to.eq(testFamily.Name);
39+
expect(resp.body.Address1).to.eq(testFamily.Address1);
40+
expect(resp.body.Email).to.eq(testFamily.Email);
41+
});
42+
});
43+
44+
it("Should return validation error for invalid family data", () => {
45+
const invalidFamily = {
46+
Name: "", // Empty name should fail validation
47+
Address1: "",
48+
City: "",
49+
State: "",
50+
Country: "",
51+
Zip: "",
52+
HomePhone: "",
53+
Email: "",
54+
people: []
55+
};
56+
57+
cy.request({
58+
method: "POST",
59+
url: "/api/public/register/family",
60+
body: invalidFamily,
61+
failOnStatusCode: false
62+
}).then((resp) => {
63+
// Should return 400 Bad Request for validation errors
64+
expect(resp.status).to.be.oneOf([400, 401]);
65+
expect(resp.body).to.have.property('error');
66+
});
67+
});
68+
});

src/ChurchCRM/Slim/Middleware/AuthMiddleware.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ class AuthMiddleware implements MiddlewareInterface
1616
{
1717
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
1818
{
19-
if (!str_starts_with($request->getUri()->getPath(), '/api/public')) {
19+
// Construct the full public API path including any subdirectory installation
20+
// Examples: '/api/public' (root install), '/crm/api/public' (subdirectory install)
21+
$publicApiPath = SystemURLs::getRootPath() . '/api/public';
22+
23+
if (!str_starts_with($request->getUri()->getPath(), $publicApiPath)) {
2024
$apiKey = $request->getHeader('x-api-key');
2125
if (!empty($apiKey)) {
2226
$logger = LoggerUtils::getAppLogger();

0 commit comments

Comments
 (0)