Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prof review #2

Open
wants to merge 165 commits into
base: prof-review-target
Choose a base branch
from
Open

Prof review #2

wants to merge 165 commits into from

Conversation

YogoGit
Copy link
Owner

@YogoGit YogoGit commented Apr 20, 2023

Code review

jgrosse01 and others added 30 commits January 27, 2023 12:26
jgrosse01 and others added 29 commits April 3, 2023 23:47
…irties context for before method instead of before class db reset
# Conflicts:
#	.gitignore
#	README.md
#	docker/Grosse_AdvSoft_App/db-primary/Dockerfile
#	docker/Grosse_AdvSoft_App/db-replica/Dockerfile
#	docker/Grosse_AdvSoft_App/docker-compose.yml
#	src/main/resources/logback-spring.xml
#	src/main/resources/templates/component-templates/css-script-tmpl.html
#	src/main/resources/templates/component-templates/footer-tmpl.html
#	src/main/resources/templates/component-templates/header-tmpl.html
#	src/main/resources/templates/component-templates/nav-tmpl.html
#	src/main/resources/templates/component-templates/table.html
#	src/main/resources/templates/index.html
#	src/main/resources/templates/ip_info.html
#	src/main/resources/templates/page-content/index.html
Copy link
Owner Author

@YogoGit YogoGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all, it's pretty good. Most of the comments are given to give you feedback and provide a way to improve the implementation and deal with a few completely bad setups, but mostly nits to make the code easier to read/maintain.

*/
override fun preHandle(req: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
log.debug("preHandle: PreHandle tracking initiated")
// ignore favicon requests
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comments!

try {
log.debug("preHandle(): Attempting to acquire client request information")
clientInfo = userAgentParser.parse(req.getHeader("User-Agent"))
ipv4 = if (req.remoteAddr == "0:0:0:0:0:0:0:1") {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making this a class constant, so the magic string address is not buried inside the code.

}
uri = req.requestURI
} catch (e: Exception) {
log.error("preHandle(): failed to parse client information")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

log.error("preHandle(): failed to parse client information", e)

[ Include the exception as the last argument anytime you have an exception to give good error logs. ]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, catching 'Exception' is considered bad practice. Instead, be more specific in the kind of exception you are expecting to catch (IOException, etc...).

log.error("preHandle(): failed to parse client information")
return false
}
trackerService.trackClient(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As has been spoke about before, trackerService.trackClient should take a DTO object for a parameters instead of a bunch of random String variables, as it easy to switch the order up accidentally, and a DTO would have setters with descriptive names that make the code easier to follow.

import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

/**
* Configuration class which registers the application interceptor as a valid interceptor to Spring
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

/**
 * Configuration class which registers the this class as an request interceptor for Spring.
 */

No need to explain how Spring/Dependency Injections works in comments, as if the readers of the code haven't gotten that part figured out with the @component annotation, they are going to be lost long before they get to this class.

Thread.sleep(100)
val timeU2f = Timestamp(Date().time)

val results = trackService.query()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One query, and then using the results. Good (unlike the previous tests in the class above).


trackService.trackClient(ipv4, browser, browserMajorVersion, platform, platformVersion, requestURI)

Thread.sleep(100)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep(1)

}

// test method disabled as there is currently no sanitization in place. this is a task for the later life
// of the project (pre-deployment but outside the scope of this semester project)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(


@Disabled
@Test
fun trackClientTestSQLInjectionUserAgent() {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No useful comments, not details, either delete or provide more context on what this test is supposed to do.


val result: MvcResult = idxMvc.perform(post(uri)).andReturn()
assertTrue(
"invalidPostMethodToIndexTest(): should not be 200 when valid URI",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is confusing. It's a valid URI, why should it fail?

[ Valid URI, invalid request type, should be in the comment. ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants