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
Add manifest-exists
rule and make other improvements
#54
Add manifest-exists
rule and make other improvements
#54
Conversation
Add rule to check if a single web app manifest file is specified, * and if that specified file is accessible.
The `::index` part wasn't being removed when calling the event and caused an exception.
@@ -98,7 +100,8 @@ const builder: CollectorBuilder = (server: Sonar, config): Collector => { | |||
|
|||
return { | |||
body, | |||
headers: response.headers | |||
headers: response.headers, | |||
statusCode: response.statusCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@molant At some point rules will also need to know the request headers, so maybe we should rename headers
to responseHeaders
, or better yet just split this into 2 objects ({ request: {}, response: {} }
). What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give me an example of why a rule should know the request headers? If they need an specific header they can pass it via customHeaders
.
If we need something else other than the headers from the response then I'd go for the 2 objects. If it is only the headers then responseHeaders
and requestHeaders
are ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give me an example of why a rule should know the request headers?
While users can make extra requests where they can set if needed custom request headers so that they control exactly how the requests are made, I think that providing the request headers will simplify some things, and in certain cases could potentially avoid some extra requests (e.g.: users can check what headers where sent by default and based on that conditionally do extra things, they can quickly use request headers while debugging).
That being said, I don't expect them to be used much, probably mostly with rules related to: content negotiation.
If we need something else other than the headers from the response
Another question is: in the future, are we considering providing any other information about the requests (e.g.: information about timing, security)?
My opinion right now is that, even if we don't expose the request headers for now, I think the response related data should be under response: {...}
so that we can add other things in the future without any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's go with request: {}, response: {}
then :)
src/tests/helpers/rule-runner.ts
Outdated
|
||
t.context.rule[event.name](eventData); | ||
event.responses.forEach((respons, i) => { // eslint-disable-line no-loop-func | ||
ruleContext.fetchContent.onCall(i).returns(Promise.resolve(respons)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: When we change this to use fixtures, another thing to consider is that it should also allow to test the value that is passed to fetchContent
.
@@ -98,7 +100,8 @@ const builder: CollectorBuilder = (server: Sonar, config): Collector => { | |||
|
|||
return { | |||
body, | |||
headers: response.headers | |||
headers: response.headers, | |||
statusCode: response.statusCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give me an example of why a rule should know the request headers? If they need an specific header they can pass it via customHeaders
.
If we need something else other than the headers from the response then I'd go for the 2 objects. If it is only the headers then responseHeaders
and requestHeaders
are ok.
|
||
In the context of [progressive web | ||
apps](https://en.wikipedia.org/wiki/Progressive_web_app), | ||
providing a web app manifest files is essential. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need more details here of what things are going to be checked. Cases where the rule will fail and when it will pass. You are checking if the file exists, that should be mentioned here:
- Missing manifest
- Duplicate manifest
- File doesn't exist
- Something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need more details here of what things are going to be checked.
Note: We should discuss at one point what exactly should the docs contain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the information that will show up in the website so it needs to be as complete as possible. Things it should have:
- Why this rule is important and when to care about it
- How to configure it if applicable
- How it behaves and what does it test exactly:
- Examples that pass the rule
- Examples that trigger the rule
- Special requirements if applicable (there might be rules that require an specific feature not supported in all collectors)
- Related links (spec, articles, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made an update before you made the above comment.
Will update / open anther PR with more information tomorrow.
src/tests/helpers/rule-runner.ts
Outdated
|
||
import { test, ContextualTestContext } from 'ava'; // eslint-disable-line no-unused-vars | ||
import { Rule, RuleBuilder, ElementFoundEvent } from '../../lib/types'; // eslint-disable-line no-unused-vars | ||
import { Rule, RuleBuilder, ElementFoundEvent, FetchResponse} from '../../lib/types'; // eslint-disable-line no-unused-vars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a better name for FetchResponse
please let me know. I'm having a hard time finding good and meaningful names :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since in developer tools, that kinda of information is displayed in the network panel, maybeNetworkData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to me, can you update the references?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/tests/helpers/rule-runner.ts
Outdated
|
||
t.context.rule[event.name](eventData); | ||
event.responses.forEach((respons, i) => { // eslint-disable-line no-loop-func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename this to response
or res
if it is already used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, sorry about the typo.
* Change `rule-runner` to allow to specify the results for requests made by `fetchContent`. * Add `statusCode` member to the `FetchResponse` interface. * Update, improve, and fix the code for the `manifest-exists` rule.
Move members of `NetworkData` interface into more specialized interfaces (i.e. `Request` and `Response`), and add those more specialised interfaces as members of `NetworkData`. This change is done in order to remove the need to work around potential naming conflicts (i.e. both the `request` and `response` have `headers`), and thus, easily allow future additions (e.g.: adding information about network timing, network security, etc.), without requiring any changes. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Ref: #54 (comment)
rule-runner
when usingelement::name::index
.manifest-exists
rule .rule-runner
allow to specify request results.