-
Notifications
You must be signed in to change notification settings - Fork 554
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
Fix #1903 - added regex check to ensure analytics/crashlytics is disabled in develop #4944
Conversation
@@ -465,3 +465,13 @@ file_content_checks { | |||
exempted_file_name: "scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt" | |||
exempted_file_name: "utility/src/main/java/org/oppia/android/util/parser/image/UrlImageParser.kt" | |||
} | |||
file_content_checks { | |||
filename_regex: ".+.xml" | |||
prohibited_content_regex: "^\s*<meta-data\s+android:name\s*=\s*"firebase_analytics_collection_deactivated"\s*android:value\s*=\s*"false".+$" |
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.
@chrislee115 Thanks for your PR! PTAL at the "Files Changed" tab on GitHub (https://github.com/oppia/oppia-android/pull/4944/files). Two questions:
- Do you need a double backslash here?
- Please add a newline at EOF.
Additionally, in your PR description, please describe how you validated the change and show screenshots as proof that it works correctly. Thanks!
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.
Adding a newline EOF.
What is the double backslash are you referring to?
Also is there a preferred way to test scrips/assets? I'm not sure if I particularly saw anything relevant in the testing guide, but I may have missed something?
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 look at the other regexes in the file, you'll see that they use a double backslash \\
instead of a single one \
, and that the single ones are highlighted by github in red. This might indicate that the backslash here is escaping the s
rather than being treated as a literal backslash. You'll probably want to double-check what works through manual testing.
For (manual) testing, I'd suggest that you create a file with prohibited content, run the script, and check that it does the right thing. Show this proof in your PR description, so that it is possible to validate that your changes actually fix the issue.
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.
Also, I'm not sure what's needed for this PR in terms of automated tests -- perhaps @BenHenning could comment. (But the above notes still apply!)
@BenHenning Adding you for this comment: #4944 (comment) Thanks! |
I'm now running some tests by running
I'm getting a bit confused on how regex works here as some things that I thought would match are not matching properly.
while this check fails:
is there some reformatting that's happening to AndroidManifest.xml that I'm not aware of? |
@chrislee115 when running your examples locally, it seems the second pattern causes testFileContent_activityDeclarationInManifest_withConfigChanges_fileContentIsNotCorrect to fail. Looking at the test file shows: Lines 1476 to 1486 in 1591524
It seems that the problem you're running into is that an existing test has an unexpected failure for that check. This is correct since every test is setting up a test-only environment that runs against all regex checks. The second test check is failing if "name=" is present, which it is for that test's AndroidManifest.xml that it's creating. |
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.
Thanks @chrislee115! The checks look good. As @seanlip mentioned it would good to have tests added for these (as you're working on), and a demonstration (e.g. screenshots) in the PR description showing these checks correctly failing when the values are reverted in the main AndroidManifest.xml file.
file_content_checks { | ||
filename_regex: ".+.xml" | ||
prohibited_content_regex: "^\\s*<meta-data\\s+android:name\\s*=\\s*"firebase_analytics_collection_deactivated"\\s*android:value\\s*=\\s*"false".+$" | ||
failure_message: "Firebase analytics collection should always be deactivated in develop" |
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.
Nit: please end with punctuation (ditto for the error below) for consistency with other errors.
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
#4949
|
} | ||
|
||
@Test | ||
fun testFileContent_activityDeclarationInManifest_withFirebaseCrashlyticsEnabled_fileContentIsNotCorrect() { |
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.
New tests here and below
testFileContent_activityDeclarationInManifest_withFirebaseCrashlyticsEnabled_fileContentIsNotCorrect()
testFileContent_activityDeclarationInManifest_withFirebaseAnalyticsEnabled_fileContentIsNotCorrect()
Hi @chrislee115, I'm going to mark this PR as stale because it hasn't had any updates for 7 days. If no further activity occurs within 7 days, it will be automatically closed so that others can take up the issue. |
I'm still not sure how to fix this issue - are there other resources I can look at? |
@chrislee115 apologize that your query still not resolved. I think @BenHenning for sure help you with your query. @BenHenning Can you please answer this discussion #4949 (comment) of @chrislee115 which blocking him to fix this regex issue. I answered his query as per my knowledge of regex but not solve his problem. Thanks. |
Done! Thanks for the highlight. |
Hi @chrislee115, I'm going to mark this PR as stale because it hasn't had any updates for 7 days. If no further activity occurs within 7 days, it will be automatically closed so that others can take up the issue. |
My apologies for the delay, was out of town - made another pull request based off this one #4995 |
…itly disab… (#4995) <!-- READ ME FIRST: Please fill in the explanation section below and check off every point from the Essential Checklist! --> ## Explanation Fix #1903 Adds a regex check in file content validation to ensure Firebase analytics are disabled in the codebase. Both regex are tested in https://regex101.com/r/l14O5J/1, https://regex101.com/r/QVHGxi/1 for Firebase analytics, Crashlytics, respectively. - "Fixes ##1903:" Adds a regex check that ensures that firebase analytics and crashlytics are explicitly disabled in AndroidManifest.xml, new pull requests based on /pull/4944 Manual testing: Case 1: firebase_analytis_collection_deactivated = false in AndroidManifest.xml; want = true (line 19)  Case 2: firebase_analytis_collection_deactivated = true not found in AndroidManifest.xml; want = explicit line (line 19)  Case 3: firebase_crashlytics_collection_enabled = true in AndroidManifest.xml; want = false (line 20)  Case 4: firebase_crashlytics_collection_enabled = false not found in AndroidManifest.xml; want = explicit line (line 20)  Case 5: happy case  ## Essential Checklist <!-- Please tick the relevant boxes by putting an "x" in them. --> - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [X] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). --------- Co-authored-by: Ben Henning <[email protected]>
Explanation
Fix #1903
Essential Checklist