mirror of https://github.com/halo-dev/halo
Fix error about response committed (#1301)
* Add index page request test * Add test for first page request * Create session before requesting contentpull/1304/head
parent
38093df0c0
commit
2b7ae41c02
|
@ -101,6 +101,7 @@ ext {
|
|||
huaweiObsVersion = "3.19.7"
|
||||
githubApiVersion = "1.84"
|
||||
templateInheritanceVersion = "0.4.RELEASE"
|
||||
jsoupVersion = "1.13.1"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -108,7 +109,7 @@ dependencies {
|
|||
implementation "org.springframework.boot:spring-boot-starter-actuator"
|
||||
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
|
||||
implementation "org.springframework.boot:spring-boot-starter-web"
|
||||
implementation "org.springframework.boot:spring-boot-starter-undertow"
|
||||
implementation "org.springframework.boot:spring-boot-starter-jetty"
|
||||
implementation "org.springframework.boot:spring-boot-starter-freemarker"
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
|
||||
|
@ -165,6 +166,7 @@ dependencies {
|
|||
testImplementation("org.springframework.boot:spring-boot-starter-test") {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
testImplementation("org.jsoup:jsoup:${jsoupVersion}")
|
||||
|
||||
developmentOnly "org.springframework.boot:spring-boot-devtools"
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ public class ContentFilter extends AbstractAuthenticationFilter {
|
|||
protected void doAuthenticate(HttpServletRequest request, HttpServletResponse response,
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
// Do nothing
|
||||
// create session
|
||||
request.getSession(true);
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
|||
|
||||
@Override
|
||||
public Set<String> getAccessPermissionStore() {
|
||||
return cacheStore.getAny(buildAccessPermissionKey(), Set.class).orElse(new HashSet());
|
||||
return cacheStore.getAny(buildAccessPermissionKey(), Set.class).orElseGet(HashSet::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package run.halo.app.it;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import run.halo.app.model.params.InstallParam;
|
||||
|
||||
/**
|
||||
* Base api test.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ActiveProfiles("test")
|
||||
class BaseApiTest {
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@LocalServerPort
|
||||
int port;
|
||||
|
||||
String blogUrl;
|
||||
|
||||
@BeforeEach
|
||||
void baseSetUp() {
|
||||
blogUrl = "http://localhost:" + port;
|
||||
}
|
||||
|
||||
void installBlog() {
|
||||
|
||||
InstallParam install = new InstallParam();
|
||||
install.setUsername("test");
|
||||
install.setNickname("test");
|
||||
install.setEmail("test@test.com");
|
||||
install.setPassword("opentest");
|
||||
install.setUrl("http://localhost:" + port);
|
||||
install.setTitle("Test's Blog");
|
||||
|
||||
restTemplate.postForObject(blogUrl + "/api/admin/installations", install,
|
||||
String.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package run.halo.app.it;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Index page request test.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Slf4j
|
||||
class IndexPageRequestTest extends BaseApiTest {
|
||||
|
||||
@Test
|
||||
void indexPage() throws IOException {
|
||||
installBlog();
|
||||
// validate atom.xml link
|
||||
Document document = Jsoup.connect(blogUrl).get();
|
||||
Element atomLink = document.head().getElementsByAttributeValue("title", "atom 1.0").get(0);
|
||||
assertEquals(blogUrl + "/atom.xml", atomLink.attr("href"));
|
||||
|
||||
// validate title link
|
||||
Element titleLink = document.body().selectFirst(".logo-title > .title > h3 > a");
|
||||
assertEquals(blogUrl, titleLink.attr("href"));
|
||||
assertEquals("Test's Blog", titleLink.text());
|
||||
|
||||
// validate post link
|
||||
Element postTitleLink =
|
||||
document.body().selectFirst(".content > .post > .post-title > h3 > a");
|
||||
assertEquals(blogUrl + "/archives/hello-halo", postTitleLink.attr("href"));
|
||||
assertEquals("Hello Halo", postTitleLink.text());
|
||||
}
|
||||
}
|
|
@ -21,18 +21,8 @@ spring:
|
|||
show-sql: true
|
||||
flyway:
|
||||
enabled: false
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 10MB
|
||||
max-request-size: 10MB
|
||||
cache:
|
||||
type: none
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
base-path: /api/admin/actuator
|
||||
exposure:
|
||||
include: [ 'httptrace', 'metrics','env','logfile' ]
|
||||
logging:
|
||||
level:
|
||||
run.halo.app: DEBUG
|
||||
|
|
Loading…
Reference in New Issue