Skip to content

Commit

Permalink
Minor update to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kadraman committed Aug 27, 2024
1 parent 1cc5b42 commit 2769894
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 131 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ installed and on your path.
To build the application using Gradle, execute the following from the command line:

```PowerShell
.\gradlew clean build -x test
.\gradlew clean build
```

## Running the Application
Expand Down Expand Up @@ -166,18 +166,18 @@ This script runs a `sourceanalyzer` translation and scan on the project's source
which you can open using the Fortify `auditworkbench` tool:

```PowerShell
auditworkbench.cmd .\IWA-Java.fpr
auditworkbench.cmd .\IWA.fpr
```

It also creates a PDF report called `IWA-Java.pdf` and optionally
It also creates a PDF report called `IWA.pdf` and optionally
uploads the results to [Fortify Software Security Center](https://www.microfocus.com/en-us/products/software-security-assurance-sdlc/overview) (SSC).

In order to upload to SSC you will need to have entries in the `.env` similar to the following:

```
SSC_URL=http://localhost:8080/ssc
SSC_AUTH_TOKEN=28145aad-c40d-426d-942b-f6d6aec9c56f
SSC_APP_NAME=IWA-Java
SSC_APP_NAME=IWA
SSC_APP_VER_NAME=main
```

Expand All @@ -197,7 +197,7 @@ In order to use ScanCentral SAST you will need to have entries in the `.env` sim
```
SSC_URL=http://localhost:8080/ssc
SSC_AUTH_TOKEN=6b16aa46-35d7-4ea6-98c1-8b780851fb37
SSC_APP_NAME=IWA-Java
SSC_APP_NAME=IWA
SSC_APP_VER_NAME=main
SCANCENTRAL_CTRL_URL=http://localhost:8080/scancentral-ctrl
SCANCENTRAL_CTRL_TOKEN=96846342-1349-4e36-b94f-11ed96b9a1e3
Expand Down Expand Up @@ -258,7 +258,7 @@ For example:

```
fcli sc-dast session login --ssc-url http://YOUR_SSC.DOMAIN -t YOUR_SSC_CI_TOKEN
fcli sc-dast scan -n "IWA-UI - FCLI" -s YOUR_SCAN_SETTINGS_ID --store curScan
fcli sc-dast scan -n "IWA - FCLI" -s YOUR_SCAN_SETTINGS_ID --store curScan
fcli sc-dast scan wait-fod ::curScan::
```

Expand Down Expand Up @@ -402,9 +402,8 @@ you will need to do for a successful invocation.

### GitHub Actions

This repository includes a [GitHub Actions](https://github.com/features/actions) example
[workflow](.github/workflows/DevSecOps.yml) that
automates the build of the application and scans the code using either
This repository includes a number of [GitHub Actions](https://github.com/features/actions) examples in the [.github/workflows](.github/workflows/) that
automate the build of the application and scans the code using either
[Fortify on Demand](https://www.microfocus.com/en-us/products/application-security-testing) or [Fortify ScanCentral](https://www.microfocus.com/en-us/cyberres/application-security/static-code-analyzer) for SAST.

### Other Pipeline Tools
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/microfocus/example/BaseSeleniumTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.microfocus.example;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/microfocus/example/DataSeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.microfocus.example.entity.*;
import com.microfocus.example.utils.EncryptedPasswordUtils;

import javax.persistence.criteria.CriteriaBuilder;
import java.time.Instant;
import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.microfocus.example.api.controllers;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.microfocus.example.api.controllers.ApiReviewController;
import com.microfocus.example.exception.ReviewNotFoundException;
import com.microfocus.example.payload.request.ReviewRequest;
import com.microfocus.example.service.ProductService;
Expand Down Expand Up @@ -165,8 +163,7 @@ void testDeleteReview() throws Exception {
MockMvcBuilders.standaloneSetup(apiReviewController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json;"));
.andExpect(MockMvcResultMatchers.status().isOk());
//.andExpect(MockMvcResultMatchers.content()
// .string("{\"success\":true,\"timestamp\":\"" + timestamp + "\",\"errors\":null}"));
}
Expand Down Expand Up @@ -198,8 +195,7 @@ void testDeleteReview3() throws Exception {
MockMvcBuilders.standaloneSetup(apiReviewController)
.build()
.perform(deleteResult)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json;"));
.andExpect(MockMvcResultMatchers.status().isOk());
//.andExpect(MockMvcResultMatchers.content()
// .string("{\"success\":true,\"timestamp\":\"" + timestamp + "\",\"errors\":null}"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.microfocus.example.api.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.microfocus.example.api.controllers.ApiSiteController;
import com.microfocus.example.api.controllers.ApiSiteController.SiteStatus;
import com.microfocus.example.entity.CustomUserDetails;
import com.microfocus.example.entity.User;
import com.microfocus.example.exception.api.ApiBadCredentialsException;
import com.microfocus.example.payload.request.LoginRequest;
Expand All @@ -18,13 +15,11 @@
import org.junit.Ignore;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
Expand All @@ -45,7 +40,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;

@ContextConfiguration(classes = {ApiSiteController.class})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.microfocus.example.api.controllers;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.microfocus.example.api.controllers.ApiUserController;
import com.microfocus.example.entity.User;
import com.microfocus.example.exception.UserNotFoundException;
import com.microfocus.example.service.UserService;
Expand Down Expand Up @@ -229,8 +227,7 @@ void testDeleteUser() throws Exception {
MockMvcBuilders.standaloneSetup(apiUserController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().contentType("application/json;"));
.andExpect(MockMvcResultMatchers.status().isOk());
//.andExpect(MockMvcResultMatchers.content()
// .string("{\"success\":true,\"timestamp\":\"" + timestamp + "\",\"errors\":null}"));
}
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/com/microfocus/example/entity/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.microfocus.example.entity.Authority;
import com.microfocus.example.entity.CustomUserDetails;
import com.microfocus.example.entity.User;

class UserTest {
/**
* Method under test: {@link User#passwordEncoder()}
Expand Down
24 changes: 0 additions & 24 deletions src/test/java/com/microfocus/example/misc/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.microfocus.example.misc;

class BaseTest {
Expand Down
25 changes: 0 additions & 25 deletions src/test/java/com/microfocus/example/misc/MoreTest.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.microfocus.example.misc;

import com.microfocus.example.misc.BaseTest;
import org.junit.Test;

public class MoreTest extends BaseTest {
Expand Down
25 changes: 0 additions & 25 deletions src/test/java/com/microfocus/example/misc/SomeTest.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.microfocus.example.misc;

import org.junit.Test;
import com.microfocus.example.misc.BaseTest;

public class SomeTest extends BaseTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.microfocus.example.payload.request;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import org.junit.Ignore;
import org.junit.jupiter.api.Test;

import com.microfocus.example.payload.request.RegisterUserRequest;

class RegisterUserRequestTest {
/**
* Method under test: {@link RegisterUserRequest#passwordEncoder()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.microfocus.example.payload.request;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.microfocus.example.entity.User;
import com.microfocus.example.payload.request.UserRequest;

import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.microfocus.example.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

import com.microfocus.example.BaseIntegrationTest;
import com.microfocus.example.DataSeeder;
import com.microfocus.example.entity.Mail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import com.microfocus.example.exception.StorageFileNotFoundException;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

import java.nio.file.Path;
import java.nio.file.Paths;

Expand All @@ -27,7 +24,6 @@
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.multipart.MultipartFile;

@ContextConfiguration(classes = {FileSystemStorageService.class, StorageProperties.class})
@ExtendWith(SpringExtension.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.microfocus.example.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

import com.microfocus.example.BaseIntegrationTest;
import com.microfocus.example.DataSeeder;
import com.microfocus.example.entity.SMS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertAll;

import java.util.Optional;

Expand Down Expand Up @@ -50,7 +52,10 @@ public void d_userService_save() {
try {
userService.saveUserFromUserForm(userForm);
Optional<User> updatedUser = userService.findUserByUsername(DataSeeder.TEST_USER1_USERNAME);
updatedUser.ifPresent(user -> assertThat(user.getFirstName()).isEqualTo("Test User 1 Updated"));
updatedUser.ifPresent(user -> assertAll(
() -> assertEquals("Test", user.getFirstName()),
() -> assertEquals("User 1 Updated", user.getLastName()))
);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import com.microfocus.example.BaseIntegrationTest;
import com.microfocus.example.DataSeeder;
import com.microfocus.example.entity.Product;
import com.microfocus.example.web.form.admin.AdminProductForm;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class VerificationServiceTest extends BaseIntegrationTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.microfocus.example.utils;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.Ignore;
import org.junit.jupiter.api.Test;

import com.microfocus.example.utils.EncryptedPasswordUtils;

class EncryptedPasswordUtilsTest {
private static final String TEST_PASSWORD_STRING = "Password123!";

Expand Down

0 comments on commit 2769894

Please sign in to comment.