Skip to content

Commit 39f7658

Browse files
committed
Improve tests and output documentation
1 parent be340f0 commit 39f7658

File tree

14 files changed

+171
-100
lines changed

14 files changed

+171
-100
lines changed

src/docs/auth.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ The `auth` endpoint exposes operations for authenticating against the API.
1515
POST /api/auth/login
1616
----
1717

18-
Authenticates a user with `username` and `password`. These values must match the values of the user's account.
18+
Authenticates a user with `username` and `password`.
19+
These values must match the values of the user's account.
1920

2021
operation::auth-token[snippets='request-fields,curl-request,response-fields,http-response']
2122

src/docs/subscriptions.adoc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
:doctype: book
33
:sectlinks:
44

5-
The `subscriptions` endpoint exposes operations taken on subscriptions. A subscriptionEntity represents two things:
5+
The `subscriptions` endpoint exposes operations taken on subscriptions.
6+
A subscriptionEntity represents two things:
67

78
1. A podcast feed
89
2. The relationship between a user and a podcast feed
@@ -18,9 +19,10 @@ POST /api/v1/users
1819
[[actions-subscriptions-create]]
1920
=== Create subscriptions
2021

21-
When a user adds a subscription to the system, a corresponding `subscriptionEntity` object is fetched or created depending on whether a matching subscriptionEntity is present. A link is then created between the user and the subscriptionEntity.
22+
When a user adds a subscription to the system, a corresponding `subscriptionEntity` object is fetched or created depending on whether a matching subscriptionEntity is present.
23+
A link is then created between the user and the subscriptionEntity.
2224

23-
operation::subscriptions-bulk-create-mixed[snippets='request-fields,curl-request,response-fields,http-response']
25+
operation::subscriptions-bulk-create-mixed[snippets='request-headers,request-fields,curl-request,response-fields,http-response']
2426

2527
==== Responses
2628

@@ -39,9 +41,10 @@ include::{snippets}/subscriptions-bulk-create-mixed/http-response.adoc[]
3941
[[actions-subscriptions-list]]
4042
=== List subscriptions
4143

42-
When a user fetches a list of subscriptions, their own subscriptions are returned. The subscriptions of other users are not returned.
44+
When a user fetches a list of subscriptions, their own subscriptions are returned.
45+
The subscriptions of other users are not returned.
4346

44-
operation::subscriptions-list[snippets='query-parameters,curl-request,response-fields,http-response']
47+
operation::subscriptions-list[snippets='request-headers,query-parameters,curl-request,response-fields,http-response']
4548

4649
==== Include unsubscribed
4750

@@ -50,13 +53,16 @@ operation::subscriptions-list-with-unsubscribed[snippets='curl-request,http-resp
5053
[[actions-subscriptionEntity-fetch]]
5154
=== Fetch a single subscriptionEntity
5255

53-
Returns the details of a single subscriptionEntity for the authenticated user. Returns `404` if the user has no subscriptionEntity entry for the feed in question.
56+
Returns the details of a single subscriptionEntity for the authenticated user.
57+
Returns `404` if the user has no subscriptionEntity entry for the feed in question.
5458

55-
operation::subscriptionEntity-get[snippets='path-parameters,curl-request,response-fields,http-response']
59+
operation::subscriptionEntity-get[snippets='request-headers,path-parameters,curl-request,response-fields,http-response']
5660

5761
[[actions-subscriptionEntity-update]]
5862
=== Unsubscribe from a feed
5963

60-
Unsubscribes the authenticated user from a feed. This action updates the user subscriptionEntity record to mark the subscriptionEntity as inactive. It does not delete the subscriptionEntity record.
64+
Unsubscribes the authenticated user from a feed.
65+
This action updates the user subscriptionEntity record to mark the subscriptionEntity as inactive.
66+
It does not delete the subscriptionEntity record.
6167

62-
operation::subscriptionEntity-unsubscribe[snippets='path-parameters,curl-request,response-fields,http-response']
68+
operation::subscriptionEntity-unsubscribe[snippets='request-headers,path-parameters,curl-request,response-fields,http-response']

src/docs/users.adoc

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,12 @@
22
:doctype: book
33
:sectlinks:
44

5-
The `users` endpoint exposes operations taken on user accounts. Users may update and delete their own user record, but only admins may update and alter the records of other users.
5+
The `users` endpoint exposes operations taken on user accounts.
6+
Users may update and delete their own user record, but only admins may update and alter the records of other users.
67

78
[[actions-users]]
89
== Actions
910

10-
[[actions-users-create]]
11-
=== Create a user
12-
13-
[source,httprequest]
14-
----
15-
POST /api/v1/users
16-
----
17-
18-
Creates a new user in the system.
19-
20-
operation::users-create[snippets='request-fields,curl-request,response-fields,http-response']
21-
22-
==== Invalid fields
23-
24-
Passing an invalid field (such as an improperly formatted email address) throws a validation error.
25-
26-
operation::users-create-bad-request[snippets='curl-request,http-response']
27-
2811
[[actions-users-get]]
2912
=== Get all users
3013

@@ -34,5 +17,6 @@ GET /api/v1/users
3417
----
3518

3619
Fetches a paginated list of users from the system.
20+
This action is restricted to users with `ADMIN` permissions.
3721

38-
operation::users-list[snippets='curl-request,response-fields,http-response']
22+
operation::users-list[snippets='request-headers,query-parameters,curl-request,response-fields,http-response']

src/main/java/org/openpodcastapi/opa/auth/ApiAuthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import jakarta.validation.constraints.NotNull;
55
import lombok.RequiredArgsConstructor;
66
import lombok.extern.log4j.Log4j2;
7-
import org.openpodcastapi.opa.config.JwtService;
7+
import org.openpodcastapi.opa.security.JwtService;
88
import org.openpodcastapi.opa.security.TokenService;
99
import org.openpodcastapi.opa.user.UserEntity;
1010
import org.openpodcastapi.opa.user.UserRepository;

src/main/java/org/openpodcastapi/opa/config/JwtAuthenticationFilter.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ private static UsernamePasswordAuthenticationToken getUsernamePasswordAuthentica
6868
protected void doFilterInternal(HttpServletRequest req, @Nonnull HttpServletResponse res, @Nonnull FilterChain chain)
6969
throws ServletException, IOException {
7070

71-
// Don't apply the check on the auth endpoints
72-
if (req.getRequestURI().startsWith("/api/auth/") || req.getRequestURI().startsWith("/docs")) {
73-
chain.doFilter(req, res);
74-
return;
75-
}
76-
7771
String header = req.getHeader(HttpHeaders.AUTHORIZATION);
7872
SecretKey key = Keys.hmacShaKeyFor(jwtSecret.getBytes(StandardCharsets.UTF_8));
7973

src/main/java/org/openpodcastapi/opa/config/SecurityConfig.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,32 @@ public class SecurityConfig {
2525
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
2626
private final JwtAccessDeniedHandler jwtAccessDeniedHandler;
2727

28+
private final String[] publicPages = {
29+
"/",
30+
"/login",
31+
"/logout-confirm",
32+
"/register",
33+
"/docs",
34+
"/docs/**",
35+
"/css/**",
36+
"/js/**",
37+
"/images/**",
38+
"/favicon.ico",
39+
};
40+
41+
private final String[] publicEndpoints = {
42+
"/api/auth/**"
43+
};
44+
2845
@Bean
2946
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
3047
http
31-
.csrf(csrf -> csrf.ignoringRequestMatchers("/api/**"))
48+
.csrf(csrf -> csrf.ignoringRequestMatchers("/api/**", "/docs", "/docs/**"))
3249
.sessionManagement(sm -> sm
3350
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // Stateless session
3451
.authorizeHttpRequests(auth -> auth
35-
.requestMatchers("/", "/login", "/logout-confirm", "/register", "/docs**", "/css/**", "/js/**", "/images/**", "/favicon.ico", "/api/auth/**").permitAll()
52+
.requestMatchers(publicPages).permitAll()
53+
.requestMatchers(publicEndpoints).permitAll()
3654
.requestMatchers("/api/v1/**").authenticated()
3755
.anyRequest().authenticated())
3856
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)

src/main/java/org/openpodcastapi/opa/config/WebConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
2020

2121
registry
2222
.addResourceHandler("/docs/**")
23-
.addResourceLocations("classpath:/docs/");
23+
.addResourceLocations("classpath:/static/docs/");
2424
}
2525

2626
@Bean

src/main/java/org/openpodcastapi/opa/docs/DocsController.java renamed to src/main/java/org/openpodcastapi/opa/controllers/DocsController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package org.openpodcastapi.opa.docs;
1+
package org.openpodcastapi.opa.controllers;
22

3+
import lombok.extern.log4j.Log4j2;
34
import org.springframework.stereotype.Controller;
45
import org.springframework.web.bind.annotation.GetMapping;
56

67
@Controller
8+
@Log4j2
79
public class DocsController {
810

911
@GetMapping("/docs")

src/main/java/org/openpodcastapi/opa/ui/controller/HomeController.java renamed to src/main/java/org/openpodcastapi/opa/controllers/HomeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.openpodcastapi.opa.ui.controller;
1+
package org.openpodcastapi.opa.controllers;
22

33
import lombok.RequiredArgsConstructor;
44
import lombok.extern.log4j.Log4j2;

src/main/java/org/openpodcastapi/opa/ui/controller/UiAuthController.java renamed to src/main/java/org/openpodcastapi/opa/controllers/UiAuthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.openpodcastapi.opa.ui.controller;
1+
package org.openpodcastapi.opa.controllers;
22

33
import jakarta.validation.Valid;
44
import lombok.RequiredArgsConstructor;

0 commit comments

Comments
 (0)