File Jenkinsfile changed (mode: 100644) (index 2c0e7d2..00fae08) |
... |
... |
pipeline{ |
12 |
12 |
{
|
{
|
13 |
13 |
stage("Compile") {
|
stage("Compile") {
|
14 |
14 |
steps {
|
steps {
|
15 |
|
sh "sh ./gradlew compileJava"
|
|
|
15 |
|
sh "sh ./gradlew compileJava --stacktrace"
|
16 |
16 |
}
|
}
|
17 |
17 |
}
|
}
|
18 |
18 |
|
|
19 |
19 |
stage("Unit test") {
|
stage("Unit test") {
|
20 |
20 |
steps {
|
steps {
|
21 |
|
sh "sh ./gradlew test --tests com.kingfisher.deployment.audit.test.unit.suite.*"
|
|
|
21 |
|
sh "sh ./gradlew test --tests com.kingfisher.deployment.audit.test.unit.suite.* --stacktrace"
|
22 |
22 |
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/reports/tests/test', reportFiles: 'index.html', reportName: 'Unit Test Report', reportTitles: 'Unit tests by Junit'])
|
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/reports/tests/test', reportFiles: 'index.html', reportName: 'Unit Test Report', reportTitles: 'Unit tests by Junit'])
|
23 |
23 |
}
|
}
|
24 |
24 |
}
|
}
|
25 |
25 |
|
|
26 |
26 |
stage('Setup dev DB instance') {
|
stage('Setup dev DB instance') {
|
27 |
27 |
steps{
|
steps{
|
28 |
|
sh "sh ./gradlew update -PrunList=dev"
|
|
|
28 |
|
sh "sh ./gradlew update -PrunList=dev --stacktrace"
|
29 |
29 |
}
|
}
|
30 |
30 |
}
|
}
|
31 |
31 |
|
|
32 |
32 |
stage("Integration test with dev DB") {
|
stage("Integration test with dev DB") {
|
33 |
33 |
steps {
|
steps {
|
34 |
|
sh "sh ./gradlew test --tests com.kingfisher.deployment.audit.test.integration.suite.*"
|
|
|
34 |
|
sh "sh ./gradlew test --tests com.kingfisher.deployment.audit.test.integration.suite.* --stacktrace"
|
35 |
35 |
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/reports/tests/test', reportFiles: 'index.html', reportName: 'Integration Test Report', reportTitles: 'Unit tests by Junit'])
|
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/reports/tests/test', reportFiles: 'index.html', reportName: 'Integration Test Report', reportTitles: 'Unit tests by Junit'])
|
36 |
36 |
}
|
}
|
37 |
37 |
}
|
}
|
|
... |
... |
pipeline{ |
39 |
39 |
stage('Test Coverage') {
|
stage('Test Coverage') {
|
40 |
40 |
steps{
|
steps{
|
41 |
41 |
// sh "sh ./gradlew check"
|
// sh "sh ./gradlew check"
|
42 |
|
sh "sh ./gradlew jacocoTestReport"
|
|
|
42 |
|
sh "sh ./gradlew jacocoTestReport --stacktrace"
|
43 |
43 |
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/reports/jacoco/test/html', reportFiles: 'index.html', reportName: 'Code Coverage Report', reportTitles: 'Code coverage by JaCoCo'])
|
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/reports/jacoco/test/html', reportFiles: 'index.html', reportName: 'Code Coverage Report', reportTitles: 'Code coverage by JaCoCo'])
|
44 |
44 |
}
|
}
|
45 |
45 |
}
|
}
|
|
... |
... |
pipeline{ |
47 |
47 |
stage("Package") {
|
stage("Package") {
|
48 |
48 |
steps {
|
steps {
|
49 |
49 |
// sh "sh ./gradlew -Dskip.tests build"
|
// sh "sh ./gradlew -Dskip.tests build"
|
50 |
|
sh "sh ./gradlew build -x test "
|
|
|
50 |
|
sh "sh ./gradlew build -x test --stacktrace"
|
51 |
51 |
}
|
}
|
52 |
52 |
}
|
}
|
53 |
53 |
|
|
|
... |
... |
pipeline{ |
92 |
92 |
|
|
93 |
93 |
stage('Setup prod DB instance') {
|
stage('Setup prod DB instance') {
|
94 |
94 |
steps{
|
steps{
|
95 |
|
sh "sh ./gradlew update -PrunList=prod"
|
|
|
95 |
|
sh "sh ./gradlew update -PrunList=prod --stacktrace"
|
96 |
96 |
}
|
}
|
97 |
97 |
}
|
}
|
98 |
98 |
|
|
File src/main/java/com/kingfisher/deployment/audit/config/security/SecurityConfig.java changed (mode: 100644) (index 22cb5e0..3b3106a) |
... |
... |
import org.springframework.security.config.annotation.web.configuration.WebSecur |
13 |
13 |
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
14 |
14 |
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
15 |
15 |
|
|
|
16 |
|
import com.kingfisher.deployment.audit.constant.ApplicationConstant;
|
16 |
17 |
import com.kingfisher.deployment.audit.exception.model.DeploymentAuditException;
|
import com.kingfisher.deployment.audit.exception.model.DeploymentAuditException;
|
17 |
18 |
import com.kingfisher.deployment.audit.security.CustomPasswordEncoder;
|
import com.kingfisher.deployment.audit.security.CustomPasswordEncoder;
|
18 |
19 |
|
|
|
... |
... |
public class SecurityConfig { |
40 |
41 |
@Override
|
@Override
|
41 |
42 |
protected void configure(HttpSecurity http) throws DeploymentAuditException {
|
protected void configure(HttpSecurity http) throws DeploymentAuditException {
|
42 |
43 |
try {
|
try {
|
43 |
|
http.csrf().disable().antMatcher("/v1/deployments/report**").authorizeRequests().anyRequest().hasRole("AUDITOR").and().httpBasic();
|
|
|
44 |
|
http.csrf().disable().antMatcher("/v1/deployments/report**").authorizeRequests().anyRequest().hasRole(ApplicationConstant.SECURITY_ROLE_AUDITOR).and().httpBasic();
|
44 |
45 |
} catch (Exception e) {
|
} catch (Exception e) {
|
45 |
46 |
throw new DeploymentAuditException(e);
|
throw new DeploymentAuditException(e);
|
46 |
47 |
}
|
}
|
|
... |
... |
public class SecurityConfig { |
53 |
54 |
@Override
|
@Override
|
54 |
55 |
protected void configure(HttpSecurity http) throws DeploymentAuditException {
|
protected void configure(HttpSecurity http) throws DeploymentAuditException {
|
55 |
56 |
try {
|
try {
|
56 |
|
http.csrf().disable().antMatcher("/v1/deployments**").authorizeRequests().anyRequest().hasRole("JENKINS").and().httpBasic();
|
|
|
57 |
|
http.csrf().disable().antMatcher("/v1/deployments**").authorizeRequests().anyRequest().hasRole(ApplicationConstant.SECURITY_ROLE_JENKINS).and().httpBasic();
|
57 |
58 |
} catch (Exception e) {
|
} catch (Exception e) {
|
58 |
59 |
throw new DeploymentAuditException(e);
|
throw new DeploymentAuditException(e);
|
59 |
60 |
}
|
}
|
|
... |
... |
public class SecurityConfig { |
66 |
67 |
@Override
|
@Override
|
67 |
68 |
protected void configure(HttpSecurity http) throws DeploymentAuditException {
|
protected void configure(HttpSecurity http) throws DeploymentAuditException {
|
68 |
69 |
try {
|
try {
|
69 |
|
http.csrf().disable().antMatcher("/v1/user/**").authorizeRequests().anyRequest().hasRole("ADMIN").and().httpBasic();
|
|
|
70 |
|
http.csrf().disable().antMatcher("/v1/user/**").authorizeRequests().anyRequest().hasRole(ApplicationConstant.SECURITY_ROLE_ADMIN).and().httpBasic();
|
70 |
71 |
} catch (Exception e) {
|
} catch (Exception e) {
|
71 |
72 |
throw new DeploymentAuditException(e);
|
throw new DeploymentAuditException(e);
|
72 |
73 |
}
|
}
|
File src/test/java/com/kingfisher/deployment/audit/test/smoke/DeploymentAuditControllerTest.java changed (mode: 100644) (index 3629826..c35dff1) |
1 |
1 |
package com.kingfisher.deployment.audit.test.smoke;
|
package com.kingfisher.deployment.audit.test.smoke;
|
2 |
2 |
|
|
3 |
3 |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
4 |
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
|
5 |
4 |
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
6 |
5 |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
7 |
6 |
|
|
|
7 |
|
import java.util.ArrayList;
|
8 |
8 |
import java.util.Arrays;
|
import java.util.Arrays;
|
|
9 |
|
import java.util.List;
|
9 |
10 |
|
|
10 |
|
import org.junit.FixMethodOrder;
|
|
11 |
11 |
import org.junit.Test;
|
import org.junit.Test;
|
12 |
12 |
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
13 |
|
import org.junit.runners.MethodSorters;
|
|
14 |
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
15 |
14 |
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
16 |
15 |
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
... |
... |
import org.springframework.test.context.ActiveProfiles; |
19 |
18 |
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
20 |
19 |
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
21 |
20 |
import com.kingfisher.deployment.audit.constant.ApplicationConstant;
|
import com.kingfisher.deployment.audit.constant.ApplicationConstant;
|
22 |
|
import com.kingfisher.deployment.audit.model.User;
|
|
|
21 |
|
import com.kingfisher.deployment.audit.model.JenkinsDeploymentStatus;
|
|
22 |
|
import com.kingfisher.deployment.audit.model.ReportParam;
|
23 |
23 |
import com.kingfisher.deployment.audit.test.util.IntegrationTestUtil;
|
import com.kingfisher.deployment.audit.test.util.IntegrationTestUtil;
|
24 |
24 |
|
|
25 |
25 |
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
26 |
26 |
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
27 |
27 |
@ActiveProfiles("dev")
|
@ActiveProfiles("dev")
|
28 |
28 |
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
29 |
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
|
30 |
29 |
public class DeploymentAuditControllerTest {
|
public class DeploymentAuditControllerTest {
|
31 |
30 |
|
|
32 |
31 |
@Autowired
|
@Autowired
|
33 |
32 |
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
34 |
33 |
|
|
35 |
|
private static final String MOCK_ADMIN_USERNAME = "admin_user";
|
|
36 |
|
private static final String MOCK_ADMIN_PASSWORD = "admin_password";
|
|
37 |
|
private static final String TEST_USER_NAME = "test_user";
|
|
38 |
|
private static final String TEST_USER_NAME2 = "test_user2";
|
|
39 |
|
private static final String TEST_USER_PASSWORD = "test_user";
|
|
40 |
|
private static final String UNKOWN_USER_NAME = "unknown_user";
|
|
|
34 |
|
private static final String MOCK_JENKINS_USERNAME = "jenkins_user";
|
|
35 |
|
private static final String MOCK_JENKINS_PASSWORD = "jenkins_password";
|
|
36 |
|
private static final String MOCK_AUDITOR_USERNAME = "auditor_user";
|
|
37 |
|
private static final String MOCK_AUDITOR_PASSWORD = "auditor_password";
|
41 |
38 |
|
|
42 |
39 |
@Test
|
@Test
|
43 |
|
@WithMockUser(username = MOCK_ADMIN_USERNAME, password = MOCK_ADMIN_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_ADMIN)
|
|
44 |
|
public void order1_testAddNewUser() throws Exception {
|
|
45 |
|
User user = new User(TEST_USER_NAME, TEST_USER_PASSWORD, Arrays.asList(new String[] { ApplicationConstant.SECURITY_USER_ROLE_ADMIN, ApplicationConstant.SECURITY_USER_ROLE_AUDITOR }));
|
|
46 |
|
this.mockMvc.perform(post("/v1/user").contentType(ApplicationConstant.CONTENT_TYPE_APPLICATION_JSON).content(IntegrationTestUtil.convertObjectToJsonString(user))).andDo(print()).andExpect(status().isCreated());
|
|
47 |
|
}
|
|
48 |
|
|
|
49 |
|
@Test
|
|
50 |
|
@WithMockUser(username = MOCK_ADMIN_USERNAME, password = MOCK_ADMIN_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_ADMIN)
|
|
51 |
|
public void order2_testUpdateExistingUser() throws Exception {
|
|
52 |
|
User user = new User(TEST_USER_NAME, TEST_USER_PASSWORD, Arrays.asList(new String[] { ApplicationConstant.SECURITY_USER_ROLE_ADMIN, ApplicationConstant.SECURITY_USER_ROLE_JENKINS }));
|
|
53 |
|
this.mockMvc.perform(post("/v1/user").contentType(ApplicationConstant.CONTENT_TYPE_APPLICATION_JSON).content(IntegrationTestUtil.convertObjectToJsonString(user))).andDo(print()).andExpect(status().isOk());
|
|
54 |
|
}
|
|
55 |
|
|
|
56 |
|
@Test
|
|
57 |
|
@WithMockUser(username = MOCK_ADMIN_USERNAME, password = MOCK_ADMIN_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_ADMIN)
|
|
58 |
|
public void order3_testUpdateNonExistingUser() throws Exception {
|
|
59 |
|
User user = new User(TEST_USER_NAME2, TEST_USER_PASSWORD, Arrays.asList(new String[] { ApplicationConstant.SECURITY_USER_ROLE_ADMIN, ApplicationConstant.SECURITY_USER_ROLE_JENKINS }));
|
|
60 |
|
this.mockMvc.perform(post("/v1/user").contentType(ApplicationConstant.CONTENT_TYPE_APPLICATION_JSON).content(IntegrationTestUtil.convertObjectToJsonString(user))).andDo(print()).andExpect(status().isCreated());
|
|
61 |
|
}
|
|
|
40 |
|
@WithMockUser(username = MOCK_JENKINS_USERNAME, password = MOCK_JENKINS_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_JENKINS)
|
|
41 |
|
public void testAdditionDeploymentRecord() throws Exception {
|
|
42 |
|
String applicationName = "Aisle_Gateway";
|
|
43 |
|
String environment = "Q";
|
|
44 |
|
String instanceName = "QIIBINST2";
|
|
45 |
|
String integrationServer = "SWEB_CNC1";
|
|
46 |
|
String deployedByUserName = "test user";
|
|
47 |
|
String deployedByUserId = "TEST_USER";
|
|
48 |
|
String createdByProcess = "auto test";
|
|
49 |
|
JenkinsDeploymentStatus jenkinsDeploymentStatus = new JenkinsDeploymentStatus(applicationName, environment, instanceName, integrationServer, deployedByUserName, deployedByUserId, createdByProcess);
|
|
50 |
|
List<JenkinsDeploymentStatus> JenkinsDeploymentStatuses = new ArrayList<>();
|
|
51 |
|
JenkinsDeploymentStatuses.add(jenkinsDeploymentStatus);
|
62 |
52 |
|
|
63 |
|
@Test
|
|
64 |
|
@WithMockUser(username = MOCK_ADMIN_USERNAME, password = MOCK_ADMIN_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_ADMIN)
|
|
65 |
|
public void order4_testRemoveExistingUser() throws Exception {
|
|
66 |
|
this.mockMvc.perform(delete("/v1/user").param("username", TEST_USER_NAME)).andDo(print()).andExpect(status().isAccepted());
|
|
|
53 |
|
this.mockMvc.perform(post("/v1/deployments").contentType(ApplicationConstant.CONTENT_TYPE_APPLICATION_JSON).content(IntegrationTestUtil.convertObjectToJsonString(JenkinsDeploymentStatuses))).andDo(print()).andExpect(status().isCreated());
|
67 |
54 |
}
|
}
|
68 |
55 |
|
|
69 |
56 |
@Test
|
@Test
|
70 |
|
@WithMockUser(username = MOCK_ADMIN_USERNAME, password = MOCK_ADMIN_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_ADMIN)
|
|
71 |
|
public void order5_testRemoveExistingUser2() throws Exception {
|
|
72 |
|
this.mockMvc.perform(delete("/v1/user").param("username", TEST_USER_NAME2)).andDo(print()).andExpect(status().isAccepted());
|
|
73 |
|
}
|
|
|
57 |
|
@WithMockUser(username = MOCK_AUDITOR_USERNAME, password = MOCK_AUDITOR_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_AUDITOR)
|
|
58 |
|
public void testGenerationDeploymentReport() throws Exception {
|
|
59 |
|
String referenceEnv = "Q";
|
|
60 |
|
List<String> reportingEnv = Arrays.asList(new String[] { "F", "V" });
|
|
61 |
|
ReportParam reportParam = new ReportParam(referenceEnv, reportingEnv);
|
74 |
62 |
|
|
75 |
|
@Test
|
|
76 |
|
@WithMockUser(username = MOCK_ADMIN_USERNAME, password = MOCK_ADMIN_PASSWORD, roles = ApplicationConstant.SECURITY_ROLE_ADMIN)
|
|
77 |
|
public void order6_testRemoveNonExistingUser() throws Exception {
|
|
78 |
|
this.mockMvc.perform(delete("/v1/user").param("username", UNKOWN_USER_NAME)).andDo(print()).andExpect(status().isNotFound());
|
|
|
63 |
|
this.mockMvc.perform(post("/v1/deployments/report").contentType(ApplicationConstant.CONTENT_TYPE_APPLICATION_JSON).content(IntegrationTestUtil.convertObjectToJsonString(reportParam))).andDo(print()).andExpect(status().isCreated());
|
79 |
64 |
}
|
}
|
80 |
65 |
} |
} |