aboutsummaryrefslogtreecommitdiff
path: root/tests/guix-hash.sh
blob: 190c9e7f8aa982853aeabf3f0f943eca0a61413c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# GNU Guix --- Functional package management for GNU
# Copyright © 2013, 2014, 2016 Ludovic Courtès <ludo@gnu.org>
# Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
#
# This file is part of GNU Guix.
#
# GNU Guix is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# GNU Guix is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

#
# Test the `guix hash' command-line utility.
#

guix hash --version

tmpdir="guix-hash-$$"
trap 'rm -rf "$tmpdir"' EXIT

test `guix hash /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
test `echo -n | guix hash -` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
test `guix hash -f nix-base32 /dev/null` = 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
test `guix hash -f hex /dev/null` = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
test `guix hash -f base32 /dev/null` = 4oymiquy7qobjgx36tejs35zeqt24qpemsnzgtfeswmrw6csxbkq

mkdir "$tmpdir"
echo -n executable > "$tmpdir/exe"
chmod +x "$tmpdir/exe"
( cd "$tmpdir" ; ln -s exe symlink )
mkdir "$tmpdir/subdir"

test `guix hash -r "$tmpdir"` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p

# Without '-r', this should fail.
if guix hash "$tmpdir"
then false; else true; fi

# This should fail because /dev/null is a character device, which
# the archive format doesn't support.
if guix hash -r /dev/null
then false; else true; fi

# Adding a .git directory
mkdir "$tmpdir/.git"
touch "$tmpdir/.git/foo"

# ...changes the hash
test `guix hash -r $tmpdir` = 0a50z04zyzf7pidwxv0nwbj82pgzbrhdy9562kncnvkcfvb48m59

# ...but remains the same when using `-x'
test `guix hash -r $tmpdir -x` = 10k1lw41wyrjf9mxydi0is5nkpynlsvgslinics4ppir13g7d74p

# Without '-r', this should fail.
if guix hash "$tmpdir"
then false; else true; fi

apos;] = st.MappingUseMode self.jinja_env.globals['versions'] = versions self.jinja_env.globals['doc_base_filename'] = 'doc_base.html.jinja' self.before_request(authenticate_by_referrer) self.before_request(choose_locale) for bp in self._haketilo_blueprints: self.register_blueprint(bp) home_bp = flask.Blueprint('home', __package__) @home_bp.route('/', methods=['GET']) def home(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response: state = _app.get_haketilo_state() html = flask.render_template( 'index.html.jinja', orphan_item_stats = state.count_orphan_items(), **errors ) return flask.make_response(html, 200) popup_toggle_action_re = re.compile( r'^popup_(yes|no)_when_(jsallowed|jsblocked|payloadon)$' ) @home_bp.route('/', methods=['POST']) def home_post() -> werkzeug.Response: action = flask.request.form['action'] state = _app.get_haketilo_state() if action == 'set_lang': new_locale = flask.request.form['locale'] assert new_locale in translations.supported_locales state.update_settings(locale=new_locale) elif action == 'use_enabled': state.update_settings(mapping_use_mode=st.MappingUseMode.WHEN_ENABLED) elif action == 'use_auto': state.update_settings(mapping_use_mode=st.MappingUseMode.AUTO) elif action == 'use_question': state.update_settings(mapping_use_mode=st.MappingUseMode.QUESTION) elif action == 'allow_scripts': state.update_settings(default_allow_scripts=True) elif action == 'block_scripts': state.update_settings(default_allow_scripts=False) elif action == 'user_make_advanced': state.update_settings(advanced_user=True) elif action == 'user_make_simple': state.update_settings(advanced_user=False) elif action == 'prune_orphans': state.prune_orphan_items() else: match = popup_toggle_action_re.match(action) if match is None: raise ValueError() popup_enable = match.group(1) == 'yes' page_type = match.group(2) settings_prop = f'default_popup_{page_type}' old_settings = getattr(state.get_settings(), settings_prop) new_settings = dc.replace(old_settings, keyboard_trigger=popup_enable) state.update_settings(default_popup_settings={page_type: new_settings}) return flask.redirect(flask.url_for('.home'), 303) @home_bp.route('/doc/<path:page>', methods=['GET']) def home_doc(page: str) -> str: if page not in self_doc.page_names: flask.abort(404) locale = t.cast(WebUIAppImpl, flask.current_app)._haketilo_request_locale if locale not in self_doc.available_locales: locale = translations.default_locale return flask.render_template( f'{locale}/{page}.html.jinja', doc_output = 'html_hkt_mitm_it' ) blueprints_main = \ (rules.bp, repos.bp, items.bp, items_import.bp, prompts.bp, home_bp) @dc.dataclass(init=False) class AppMain(WebUIAppImpl): _haketilo_blueprints = blueprints_main _haketilo_ui_domain = _app.UIDomain.MAIN landing_bp = flask.Blueprint('landing_page', __package__) @landing_bp.route('/', methods=['GET']) def landing(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response: state = _app.get_haketilo_state() html = flask.render_template( 'landing.html.jinja', listen_host = state.listen_host, listen_port = state.listen_port ) return flask.make_response(html, 200) @dc.dataclass(init=False) class AppLandingPage(WebUIAppImpl): _haketilo_blueprints = (landing_bp,) _haketilo_ui_domain = _app.UIDomain.LANDING_PAGE apps_seq = [AppMain(), AppLandingPage()] apps = dict((app._haketilo_ui_domain, app) for app in apps_seq) def process_request( request_info: http_messages.RequestInfo, state: st.HaketiloState, ui_domain: _app.UIDomain = _app.UIDomain.MAIN ) -> http_messages.ResponseInfo: path = '/'.join(('', *request_info.url.path_segments)) if (request_info.url.has_trailing_slash): path += '/' app = apps[ui_domain] with app._haketilo_app_lock: app._haketilo_state = state flask_response = app.test_client().open( path = path, base_url = request_info.url.url_without_path, method = request_info.method, query_string = request_info.url.query, headers = [*request_info.headers.items()], data = request_info.body ) headers_bytes = [ (key.encode(), val.encode()) for key, val in flask_response.headers ] return http_messages.ResponseInfo.make( status_code = flask_response.status_code, headers = headers_bytes, body = flask_response.data )