31 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
87331e7c97
gitweb: Don't use privileged action feature to run as different user
- Instead implement running specific commands inside the privileged action as a
specific user.

Tests:

- Gitweb functional tests and unit tests work.

- Running various operations such as clone, create, set branch, rename, etc. all
result in repositories (and all their contents) owned by www-data:www-data.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-09-05 20:22:40 +05:30
Sunil Mohan Adapa
7a4fb9d9f6
gitweb: Use pathlib API more
Tests:

- Existing gitweb repos are listed properly. Newly created repos are reported
  properly.

  - Directories without .git extension or starting with . are not shown.

  - Private repos are shown as private and public ones as public.

- Cloning progress is shown properly in the list of repos.

  - Cloning starts with 0%.

  - Cloning file is removed after completion of cloning process.

  - Cloning is done into .temp directory.

  - After cloning repo can be checked out as expected.

- Getting/setting of default branch/description/owner/private works.

- Getting the list of branches work when selecting the default branch.

- Creating new blank repo works.

- Deleting a repo works

- Uninstalling the app works. All repos are removed.

- Retrieving non-existent repo shows error as expected

- Backup/restore of repos works as expected.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-09-05 20:22:15 +05:30
Veiko Aasa
1268898176
gitweb: Fix modifying git repositories when gitweb app is disabled
Fixes #2408.

- When app is disabled, continue to update the app shortcut's login required
property. Otherwise, the value is current after the app is re-enabled.

- When public access is enabled, the gitweb-freedombox-auth.conf configuration
must be disabled. This can be done even if the configuration is already disabled
or does not exist. So, continue doing this.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Perform enable public access even if app is disabled]
[sunil: Perform shortcut update in all cases even if app is disabled]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-02-27 15:06:27 -08:00
Sunil Mohan Adapa
d32d02ecb5
gitweb, users: Minor fixes for newer pycodestyle
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-02-21 20:54:47 -05:00
James Valleroy
143188a363
gitweb: Disable gpg signing in tests
In case the local git config has gpg signing enabled for commits, it
causes the test commit to fail. Ensure gpg signing is disabled to
avoid this failure.

Tests:

- Gitweb functional tests passed. (Randomly there is a failure, but
  seems unrelated, see #2349.)

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2023-05-19 22:21:56 +03:00
Sunil Mohan Adapa
f2ecd3c46e
gitweb: tests: Skip tests using git when git is not installed
Tests:

- Unit tests work when git is not installed. Marked tests are skipped.

- Unit tests work when git is installed. Marked tests are not skipped.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-01-30 20:08:14 -05:00
Sunil Mohan Adapa
b91f1cf922
gitweb: Use privileged decorator for actions
Tests:

- Functions tests work
- Initial setup works
  - Global default branch is set to 'main'
- Creating an repository works
- Cloning a repository works
  - Progress is shown on the app page
- List of repositories is shown properly in the app page
- Deleting a repo works
- Editing a repository works
  - Repository information is shown properly in the form
  - Renaming a repository
  - Setting description
  - Setting owner
  - Setting a repository private/public
  - Setting default branch (list of branches is shown properly)
  - Error is thrown properly when a remote repository does not exist
- Errors are handled properly when creating/editing/deleting repo

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:52:02 -04:00
Sunil Mohan Adapa
2454527740
gitweb: tests: functional: Find forms more accurately
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-09-03 17:28:41 -04:00
Sunil Mohan Adapa
900c0d30b9
*: Drop module level app property
module.app property usage is greatly reduced because setup() and force_upgrade()
method are now part of App class instead of at the module level. Remove the
remaining minor cases of usage and drop the property altogether.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:29 -04:00
Veiko Aasa
545b35c0aa
gitweb: Switch default branch name to main for new repositories
I tested additionally that if the root user has already configured
default branch other than main, it is not changed by the gitweb app
setup process.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-15 20:54:32 -04:00
James Valleroy
55fd53a18c
gitweb: Use BaseAppTests for functional tests
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-11-08 11:51:14 -08:00
Sunil Mohan Adapa
344915d84e
gitweb: tests: Use common fixtures for testing actions module
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2021-09-25 12:41:00 +03:00
Veiko Aasa
c5c1f5594d
gitweb: tests: functional: Fix test failure if initial default branch is not master
Closes #2101.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-09-18 00:04:33 -07:00
Veiko Aasa
00be64036a
gitweb: tests: Convert functional tests to non-BDD python format
Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-09-18 00:04:24 -07:00
Veiko Aasa
abbec6b8e9
gitweb: tests: Fix test failures if initial default branch is not master
Since Git 2.28, it is possible to change initial default branch name using
the configuration option init.defaultBranch.

Closes #2101.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-09-09 12:50:38 -07:00
Veiko Aasa
504d0cdf00
gitweb: Add functional tests for git-access group
Add functional tests:
- User of git-access group can access gitweb site.
- User not of git-access group can't access gitweb site.

Tested that all the gitweb app tests pass.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2021-01-10 20:16:50 +05:30
Veiko Aasa
7cf166e558
gitweb: tests: functional: Fix test failures in localized environment
Closes #2005

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Fioddor Superconcentrado <fioddor@gmail.com>
2021-01-05 22:38:55 +01:00
Veiko Aasa
9a6fa83376
gitweb: Make functional tests compatible with pytest-bdd v4.0
In pytest-bdd v4.0, given steps are no longer fixtures.

- Make gitweb_repo_metadata a fixture.
- Remove errorneous fixture usage from the gitweb_repo_should_not_exist
  step (fixture gitweb_repo returned always None).

Tested that gitweb functional tests pass when using pytest v4.0.2

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-12-19 09:49:23 -05:00
Veiko Aasa
c136f27707
gitweb: Add ability to change default branch
Now it is possible to change default branch when editing a repository.

Gitweb site shows default branch as a main branch and the 'git clone'
command checks out to default branch.

Added unit and functional tests. Splitted one large 'test_actions'
into multiple tests.

Tests performed:
- All gitweb unit and functional tests pass.
- Created a repository from a remote repository which has default
  branch other than master. Confirmed that the 'Edit repository'
  page shows correct branch and gitweb site shows this branch as
  a default branch

Closes #1925

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-09-09 14:37:17 -07:00
Veiko Aasa
eb7454d3b7
gitweb: Fix enable auth webserver component on app init
* Fixes the gitweb app initalization when there are no public
repositories and the apache2 configuration gitweb-freedombox-auth has
not been enabled before (this may happen when the git repositories or
apache2 configuration has been modified outside the plinth web UI).
* Fix comment in the gitweb-freedombox-auth.conf apache2 configuration
file.

Fixes #1928

Tests performed:
* The gitweb app unit and functional tests pass.
* Configured all gitweb repositories as private. Stopped the plinth
service. Disabled the apache2 configuration gitweb-freedombox-auth.
Then starting the plinth service succeeds and gitweb-freedombox-auth
configuration gets enabled.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2020-08-22 12:25:24 +05:30
Sunil Mohan Adapa
80dff7bf9c
tests: functional: Re-organize step definitions and helper methods
- Move non-reusable app specific step definitions and helper methods into
<app>/tests/test_functional.py.

- Merge reusable helper methods into plinth.tests.functional

- Merge reusable step definitions into plinth.tests.functional.step_definitions

- avahi, datetime, ikiwiki: Reuse common methods to avoid repetition. Avoid
mapping from app nicknames to actual app names.

- deluge, transmission: Make a copy of sample.torrent for each app to avoid
clogging common place.

- Implement functional.visit() to simplify a lot of browser.visit() calls.

- Ensure that name of the mark on functional tests for an app is same as name of
the app. This will help with predicting the mark when running tests for a
particular app.

Tests performed:

- Run all functional tests.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2020-05-22 22:52:40 +05:30
Sunil Mohan Adapa
80d67c2054
tests: functional: Merge into main source hierarchy
- Add pytest hooks to ignore all functional tests if pytest_bdd is not
installed.

- Update pytest hooks to skip tests in file named 'test_functional.py' if
--include-functional argument is not provided.

- Move functional_tests/install.py into plinth/tests/functional and update
reference in Vagrantfile.

- Move scenario files into individual app folders. Rename them after the app
they are testing. Merge TODO items listed in todo.org into corresponding feature
files.

- Add test_functional.py in each app to build tests from the features file using
pytest_bdd.

- Move all step_definitions, support and data into plinth/tests/functional/.
Include all step_definitions from conftest.py. Update to relative imports
instead of absolute imports.

Tests performed:

- Run py.test-3 --collect-only shows all functional tests and lists 574 tests.
No errors show that name of feature files are correct. The number says that all
functional test features are included.

- Remove pytest_bdd (or modify the import name) and run py.test-3 --collect-only
skips collecting all functional tests and shows only 300+ tests.

- Run functional tests for a few apps with py.test-3 --include-functional -m
app. For storage, deluge.

- Run unit tests with py.test-3. Functional tests are listed by skipped.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2020-05-22 21:26:05 +05:30
Veiko Aasa
d26e87661b
gitweb: Improve error handling when creating repository
If an error occurs during creation of a git repository, delete possibly
corrupted git repository directory and show more specific error message.

Closes #1829

Tests performed:
- Gitweb unit and functional tests pass
- Create a small disk for git repositories:
  > dd if=/dev/zero of=disk.img iflag=fullblock bs=128k count=100 && sync
  > mkfs.ext4 disk.img
  > mount -o loop disk.img /var/lib/git/
- Clone a large repository https://salsa.debian.org/freedombox-team/plinth
  Disk got full during cloning remote repository. Repository listing do not
  show this repository anymore. (No errors is shown to the user.)
- Fill disk space:
  > head -c 1G </dev/urandom > /var/lib/git/myfile
- Disk is full. Cloning an existing remote repository fails with an error
  message (No space left on device)
- Disk is full. Creating a new repository fails with an error message
  (No space left on device)

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-04-18 15:23:11 -04:00
Sunil Mohan Adapa
9368504da5
*.py: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:38:55 +02:00
Sunil Mohan Adapa
9e166f799c
gitweb: Fix flake8 error that is causing pipeline failures
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-01-02 17:49:02 -08:00
Veiko Aasa
171f2976cf
gitweb: Add tests for views
- Delete unused key from repo info dict
- Rename actions test file

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Make URLs setup cleanup properly, minor cosmetics and warning fixes]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-01-02 16:31:37 -08:00
Alice Kile
eb83e00011
fix formatting issues
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-07 13:08:35 -05:00
Veiko Aasa
c99b33b40e
gitweb: Allow to import from a remote repository
- Allow to enter either name or URL when creating repository

- Validate a repository URL, allow only http and https schemes

- Set autocomplete off on the name/URL field because URL may contain
  username:password

- Check whether the repository actually exists before cloning

- Show progress info while cloning

- Actions script: new subcommand check-repo-exists and new arguments
  for the create-repo: --url, --prepare-only and --skip-prepare

- Add test for invalid URLs

Closes #1670

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Fix validating repo name in edit form]
[sunil: Don't pipe stdin of clone process, it may lead to a hang]
[sunil: Always run clone process with 'C' locale since we are parsing output]
[sunil: Cosmetic changes]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-11-04 21:16:30 -08:00
Veiko Aasa
ba9869c030
gitweb: Validate repository name also in actions script
This prevents writing to an arbitrary directory if running actions script
as a root user.

- Included tests for invalid names

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil@medhas.org Parametrize the test case]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-10-28 11:22:20 -07:00
Veiko Aasa
c8eb5bb3ca
gitweb: Add tests for actions script
- add tests for create, edit and delete repository functions
- modify actions script to allow run actions without root privileges:
  - add argument --git-repo-root to overwrite the default root directory
    of repositories
  - add option --keep-ownership to the create-repo command to skip
    changing ownership to www-data
- actions script, repo-info command: instead of returning empty values,
  raise an error if the repository doesn't exist

Closes #1667

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil@medhas.org Remove unneeded #! directive]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-10-26 21:27:28 -07:00
Veiko Aasa
1b9dea4033
gitweb: New app for simple git hosting
Closes: #1658

Signed-off-by: Veiko Aasa veiko17@disroot.org
[sunil@medhas.org Minor styling and cosmetic changes]
[sunil@medhas.org Write comments for Apache configurations]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-10-19 19:13:54 -07:00