Skip to content

Commit

Permalink
Merge branch 'nodiscc-cleanup-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
pyllyukko committed Jul 8, 2023
2 parents 9073ae0 + 3779a7c commit 8e55d26
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 91 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI
on:
push:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install test utilities
run: sudo apt install make node-acorn shellcheck
- name: Run tests
run: make tests
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

129 changes: 60 additions & 69 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,71 +1,60 @@
SHELL=/bin/bash

.PHONY: all
all: whatdoesitdo tests

##### INSTALLATION METHODS #####

.PHONY: locked_user.js # generate a locked configuration file
locked_user.js: user.js
######## generate a locked configuration file
sed 's/^user_pref/lockPref/' $< >| $@
sed 's/^user_pref/lockPref/' $< >| locked_user.js

.PHONY: systemwide_user.js # generate a system-wide configuration file
systemwide_user.js: user.js
######## generate a system-wide configuration file
sed 's/user_pref(/pref(/' $< >| $@
sed 's/user_pref(/pref(/' $< >| systemwide_user.js

.PHONY: debian_locked.js # # generate a locked, system-wide configuration file
debian_locked.js: user.js
######## generate a locked, system-wide configuration file
sed 's/^user_pref(\("[^"]\+"\),\s\+\([^)]\+\));\(\s*\/\/.*\)\?$$/pref(\1, \2, locked);/' $< >| $@
sed 's/^user_pref(\("[^"]\+"\),\s\+\([^)]\+\));\(\s*\/\/.*\)\?$$/pref(\1, \2, locked);/' $< >| debian_locked.js

# https://github.com/mozilla/policy-templates/blob/master/README.md
.PHONY: policies.json # generate policy file (https://github.com/mozilla/policy-templates/blob/master/README.md)
policies.json:
# TODO what does it do?
jq -n -M "{\"policies\": {\"OfferToSaveLogins\": false, \"DisableBuiltinPDFViewer\": true, \"DisablePocket\": true, \"DisableFormHistory\": true, \"SanitizeOnShutdown\": true, \"SearchBar\": \"separate\", \"DisableTelemetry\": true, \"Cookies\": {\"AcceptThirdParty\": \"never\", \"ExpireAtSessionEnd\": true}, \"EnableTrackingProtection\": {\"Value\": true}, \"PopupBlocking\": {\"Default\": true}, \"FlashPlugin\": {\"Default\": false}, \"DisableFirefoxStudies\": true}}" >| $@
jq -n -M "{\"policies\": {\"OfferToSaveLogins\": false, \"DisableBuiltinPDFViewer\": true, \"DisablePocket\": true, \"DisableFormHistory\": true, \"SanitizeOnShutdown\": true, \"SearchBar\": \"separate\", \"DisableTelemetry\": true, \"Cookies\": {\"AcceptThirdParty\": \"never\", \"ExpireAtSessionEnd\": true}, \"EnableTrackingProtection\": {\"Value\": true}, \"PopupBlocking\": {\"Default\": true}, \"FlashPlugin\": {\"Default\": false}, \"DisableFirefoxStudies\": true}}" >| policies.json


##### TESTS #####
# Requirements: node-acorn shellcheck

.PHONY: tests
tests: sourceprefs.js checkdeprecated stats acorn bash_syntax shellcheck
.PHONY: tests # run all tests
tests: test-acorn test-shellcheck

.PHONY: acorn
acorn:
######## validate js syntax
.PHONY: test-acorn # validate user.js syntax
test-acorn:
acorn --silent user.js

.PHONY: bash_syntax
bash_syntax:
######## check syntax of all bash scripts
$(foreach i,$(wildcard *.sh),bash -n $(i);)

.PHONY: shellcheck
shellcheck:
######## check/lint all shell scripts
.PHONY: test-shellcheck # check/lint shell scripts
test-shellcheck:
shellcheck *.sh


##### MAINTENANCE #####
##### DIFF GENERATION/COMPARISONS WIT UPSTREAM/TOR BROWSER #####

TBBBRANCH=tor-browser-68.8.0esr-9.5-1
000-tor-browser.js:
######## download Tor Browser custom configuration reference
wget -nv "https://gitweb.torproject.org/tor-browser.git/plain/browser/app/profile/firefox.js?h=$(TBBBRANCH)" -O $@

regex = ^\(user_\)\?pref/s/^.*pref("\([^"]\+\)",\s*\([^)]\+\).*$$
.PHONY: tbb-diff
tbb-diff: 000-tor-browser.js
######## differences between values from this user.js and tor browser's values
diff <(sed -n '/$(regex)/\1 = \2/p' user.js | sort) <(sed -n '/$(regex)/\1 = \2/p' $< | sort)

.PHONY: tbb-diff-2
tbb-diff-2: 000-tor-browser.js
######## TODO what does it do?
for setting in $$( comm -12 <(sed -n '/$(regex)/\1/p' user.js | sort) <(sed -n '/$(regex)/\1/p' $< | sort)); do diff <(grep "^\(user_\)\?pref(\"$${setting}\"" user.js | sed -n '/$(regex)/\1 = \2/p' | sort) <(grep "^\(user_\)\?pref(\"$${setting}\"" $< | sed -n '/$(regex)/\1 = \2/p' | sort); done

.PHONY: tbb-missing-from-user.js
tbb-missing-from-user.js: 000-tor-browser.js
######## preferences that are present in tor browser's defaults, but not in this user.js
comm -13 <(sed -n '/$(regex)/\1/p' user.js | sort) <(sed -n '/$(regex)/\1/p' $< | sort)
.PHONY: diff-000-tor-browser.js # download Tor Browser custom configuration reference
diff-000-tor-browser.js:
wget -nv "https://gitweb.torproject.org/tor-browser.git/plain/browser/app/profile/firefox.js?h=$(TBBBRANCH)" -O 000-tor-browser.js

PREF_REGEX = ^\(user_\)\?pref/s/^.*pref("\([^"]\+\)",\s*\([^)]\+\).*$$
.PHONY: diff-tbb # differences between values from this user.js and tor browser's values
diff-tbb: 000-tor-browser.js
diff <(sed -n '/$(PREF_REGEX)/\1 = \2/p' user.js | sort) <(sed -n '/$(PREF_REGEX)/\1 = \2/p' $< | sort)

.PHONY: diff-tbb-2 # differences between values from this user.js and tor browser's values (alternate method)
diff-tbb-2: 000-tor-browser.js
for setting in $$( comm -12 <(sed -n '/$(PREF_REGEX)/\1/p' user.js | sort) <(sed -n '/$(PREF_REGEX)/\1/p' $< | sort)); do diff <(grep "^\(user_\)\?pref(\"$${setting}\"" user.js | sed -n '/$(regex)/\1 = \2/p' | sort) <(grep "^\(user_\)\?pref(\"$${setting}\"" $< | sed -n '/$(regex)/\1 = \2/p' | sort); done

.PHONY: diff-tbb-missing-from-user.js # preferences that are present in tor browser's defaults, but not in this user.js
diff-tbb-missing-from-user.js: 000-tor-browser.js
comm -13 <(sed -n '/$(PREF_REGEX)/\1/p' user.js | sort) <(sed -n '/$(PREF_REGEX)/\1/p' $< | sort)

# specify wanted Firefox version/revision below (eg. "tip", "FIREFOX_AURORA_45_BASE", "9577ddeaafd85554c2a855f385a87472a089d5c0"). See https://hg.mozilla.org/mozilla-central/tags
SOURCEVERSION=tip
Expand All @@ -82,55 +71,57 @@ FIREFOX_SOURCE_PREFS= \
https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/branding/aurora/pref/firefox-branding.js \
https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/locales/en-US/firefox-l10n.js \
https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/app/profile/channel-prefs.js
sourceprefs.js:
######## download and sort all known preferences files from Firefox (mozilla-central) source
@for SOURCEFILE in $(FIREFOX_SOURCE_PREFS); do wget -nv "$$SOURCEFILE" -O - ; done | egrep "(^pref|^user_pref)" | sort --unique >| $@
.PHONY: diff-sourceprefs.js # download and sort all known preferences files from Firefox (mozilla-central) source
diff-sourceprefs.js:
@for SOURCEFILE in $(FIREFOX_SOURCE_PREFS); do wget -nv "$$SOURCEFILE" -O - ; done | egrep "(^pref|^user_pref)" | sort --unique >| sourceprefs.js

.PHONY: upstream-duplicates
upstream-duplicates: sourceprefs.js
######## preferences with common values with default Firefox configuration
.PHONY: diff-upstream-duplicates # preferences with common values with default Firefox configuration
diff-upstream-duplicates: diff-sourceprefs.js
@sed 's/^pref(/user_pref(/' sourceprefs.js | sed -E "s/[[:space:]]+/ /g" | sort > sourceprefs_sorted.js
@grep "^user_pref" user.js | sed -E "s/[[:space:]]+/ /g" | sort > userjs_sorted.js
@comm -1 -2 sourceprefs_sorted.js userjs_sorted.js

.PHONY: upstream-missing-from-user.js
upstream-missing-from-user.js: sourceprefs.js
######## preferences present in firefox source but not covered by user.js
######## configure ignored preferences in ignore.list
.PHONY: diff-upstream-missing-from-user.js # preferences present in firefox source but not covered by user.js
diff-upstream-missing-from-user.js: diff-sourceprefs.js
# configure ignored preferences in ignore.list
@SOURCE_PREFS=$$(egrep '(^pref|^user_pref)' $< | awk -F'"' '{print $$2}'); \
for SOURCE_PREF in $$SOURCE_PREFS; do \
grep "\"$$SOURCE_PREF\"" user.js ignore.list >/dev/null || echo "Not covered by user.js : $$SOURCE_PREF"; \
done | sort --unique

.PHONY: checkdeprecated
upstream-deprecated: sourceprefs.js
######## preferences in hardened user.js that are no longer present in firefox source
.PHONY: diff-upstream-deprecated # preferences in hardened user.js that are no longer present in firefox source
diff-upstream-deprecated: diff-sourceprefs.js
@HARDENED_PREFS=$$(egrep "^user_pref" user.js | cut -d'"' -f2); \
for HARDENED_PREF in $$HARDENED_PREFS; do \
grep "\"$$HARDENED_PREF\"" $< >/dev/null || echo "Deprecated : $$HARDENED_PREF"; \
done | sort --unique

.PHONY: stats
stats: sourceprefs.js
######## count preferences number, various stats
.PHONY: diff-stats # count preferences number, various stats
diff-stats: diff-sourceprefs.js
@echo "$$(egrep "^user_pref" user.js | wc -l | cut -f1) preferences in user.js"
@echo "$$(wc -l $< | cut -d" " -f1) preferences in Firefox source"

.PHONY: whatdoesitdo
whatdoesitdo:
######## generate the README "What does it do?" section
@./gen-readme.sh

.PHONY: clean
##### MISC #####

.PHONY: clean # clean automatically generated files/build/test artifacts
clean:
######## generate/update the README "What does it do?" section
@rm -f sourceprefs.js sourceprefs_sorted.js userjs_sorted.js 000-tor-browser.js debian_locked.js
@rm -f sourceprefs.js sourceprefs_sorted.js userjs_sorted.js 000-tor-browser.js debian_locked.js systemwide_user.js

##### DOCUMENTATION GENERATION #####

.PHONY: toc
toc:
######## generate the README table of contents
.PHONY: doc-whatdoesitdo # generate the README "What does it do?" section
doc-whatdoesitdo:
@./gen-readme.sh

.PHONY: doc-toc # generate the README table of contents
doc-toc:
@l2headers=$$(egrep "^## " README.md |cut -d" " -f1 --complement ); \
echo "$$l2headers" | while read line; do \
anchor=$$(echo "$$line" | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g' | sed 's/\?//g'); \
echo "* [$$line](#$$anchor)"; \
done

.PHONY: help # generate list of targets with descriptions
help:
@grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1 \2/' | expand -t20
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A [user.js](http://kb.mozillazine.org/User.js_file) configuration file for [Mozi

**This is a default template with every possible hardening measure enforced. See the [relaxed branch](https://github.com/pyllyukko/user.js/tree/relaxed) for a variant providing more usability**

[![Build Status](https://travis-ci.org/pyllyukko/user.js.svg?branch=master)](https://travis-ci.org/pyllyukko/user.js)
[![Build Status](https://github.com/pyllyukko/user.js/actions/workflows/ci.yml/badge.svg)](https://github.com/pyllyukko/user.js/actions)

### Main goals

Expand Down Expand Up @@ -38,6 +38,7 @@ There are several parts to all this and they are:
* [Contributing](#contributing)
* [Online tests](#online-tests)
* [References](#references)
* [Maintenance](#maintenance)


----------------------------------------------
Expand Down Expand Up @@ -604,6 +605,38 @@ For more information, see [CONTRIBUTING](https://github.com/pyllyukko/user.js/bl

--------------------------------------------------------------------------

## Maintenance

Run `make help` to get a list of makefile targets used for frequent maintenance operations.

```
$ make help
locked_user.js generate a locked configuration file
systemwide_user.js generate a system-wide configuration file
debian_locked.js # generate a locked, system-wide configuration file
policies.json generate policy file (https://github.com/mozilla/policy-templates/blob/master/README.md)
tests run all tests
test-acorn validate user.js syntax
test-bash-syntax check syntax of all bash scripts
test-shellcheck check/lint shell scripts
diff-000-tor-browser.js download Tor Browser custom configuration reference
diff-tbb differences between values from this user.js and tor browser's values
diff-tbb-2 differences between values from this user.js and tor browser's values (alternate method)
diff-tbb-missing-from-user.js preferences that are present in tor browser's defaults, but not in this user.js
diff-sourceprefs.js download and sort all known preferences files from Firefox (mozilla-central) source
diff-upstream-duplicates preferences with common values with default Firefox configuration
diff-upstream-missing-from-user.js preferences present in firefox source but not covered by user.js
diff-upstream-deprecated preferences in hardened user.js that are no longer present in firefox source
diff-stats count preferences number, various stats
clean clean automatically generated files/build/test artifacts
doc-whatdoesitdo generate the README "What does it do?" section
doc-toc generate the README table of contents
help generate list of targets with descriptions
```

-----------------------------

[2]: https://wiki.mozilla.org/Security:Renegotiation#security.ssl.require_safe_negotiation
[8]: https://support.mozilla.org/en-US/kb/Private%20Browsing
[9]: https://bugzilla.mozilla.org/show_bug.cgi?id=822869
Expand Down

0 comments on commit 8e55d26

Please sign in to comment.