Giter Club home page Giter Club logo

scheduler's Introduction

๐Ÿ’ป JAVA DEVELOPER

โญ programming enthusiast ๐ŸŽง music fanatic

LinkedIn Stack Overflow Gmail LinkedIn

Main tech stack

java spring spring

scheduler's People

Contributors

dudiic avatar

Watchers

 avatar

scheduler's Issues

Wrong date format in errors

Change the date format to 24-hour (currently 12-hour) and fix incorrectly specifying minutes (do not match the actual state of affairs).

Visible password

When attempting to register a user, if the password is not correct, the JSON returns an unhashed string containing the proposed password in response. For example:

{
    "timestamp": "2021-05-03 13:06:33",
    "status": "400 BAD_REQUEST",
    "message": "Validation error",
    "details": [
        {
            "object": "registerDto",
            "field": "password",
            "rejectedValue": "PROPOSED PASSWORD", <<<=== visible password here 
            "message": "password must be 8-24 characters long"
        }
    ]
}

Sonarqube issue #6

Remove duplicates in this character class.

@NotNull(message = "password is required")
@Size(
min = 8, max = 24,
message = "password must be 8-24 characters long"
)
@Pattern(regexp = ".*[a-z].*", message = "password must contains at least one lowercase")
@Pattern(regexp = ".*[A-Z].*", message = "password must contains at least one lowercase")
@Pattern(regexp = ".*\\d.*", message = "password must contains at least one digit")
@Pattern(regexp = ".*[!@#$%&*()_+=|<>?{}\\\\[\\\\]~-].*", message = "password must contains at least one special character")
String password;

SonarCloud linked issue

Refactoring `JwtAuthTest`

After getting to know the libraries for testing better, I noticed a lot of anomalies and bad practices in this test class.

First, instead of marking everything with @Autowired annotation, you can provide implementations using mockito, not using the entire spring, and an additional database for testing (because these are no longer unit tests). Like here:

@Autowired
private UserRepository userRepository;

This should have a significant impact on the test execution time because at the moment you can see a big difference to the other test classes.

image

Sonarqube Security Hotspot #2

Make sure the regex used here, which is vulnerable to polynomial runtime due to backtracking, cannot lead to denial of service.

@Pattern(regexp = "^[a-zA-Z0-9]+$", message = "username can only consist of alphanumeric characters")
private String username;

@Pattern(regexp = ".*[a-z].*", message = "password must contains at least one lowercase")
@Pattern(regexp = ".*[A-Z].*", message = "password must contains at least one lowercase")
@Pattern(regexp = ".*\\d.*", message = "password must contains at least one digit")
@Pattern(regexp = ".*[!@#$%&*()_+=|<>?{}\\[\\]~-].*", message = "password must contains at least one special character")
private String password;

SonarCloud linked hotspot

Sonarqube issue #2

Use try-with-resources or close this "ServletServerHttpResponse" in a "finally" clause.

public void handle(
HttpServletRequest request,
HttpServletResponse response,
AccessDeniedException accessDeniedException)
throws IOException, ServletException {
ServletServerHttpResponse res = new ServletServerHttpResponse(response);
res.setStatusCode(HttpStatus.FORBIDDEN);
res.getServletResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);

SonarCloud linked issue 1

public void commence(
HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception)
throws IOException, ServletException {
ServletServerHttpResponse res = new ServletServerHttpResponse(response);
res.setStatusCode(HttpStatus.UNAUTHORIZED);
res.getServletResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);

SonarCloud linked ussue 2

Login endpoint in OpenAPI

To generate the documentation, a controller without implementation was created.

@RestController
@RequestMapping("/api/v1/login")
@Tag(name = "login")
class LoginController {
@PostMapping
public BearerToken login(@RequestBody AuthCredentials authCredentials){
return new BearerToken();
}
}

There is no information that the logic is implemented elsewhere.

The best solution is to rebuild so that authorization is done with a dedicated service instead of a request handler (based on this post).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.