File: commons

package info (click to toggle)
pass-update 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: sh: 658; makefile: 70; python: 52
file content (165 lines) | stat: -rw-r--r-- 5,150 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
# pass update - Password Store Extension (https://www.passwordstore.org/)
# Copyright (C) 2017 Alexandre PUJOL <alexandre@pujol.io>.
#
#    This program 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.
#
#    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
# This file should be sourced by all test-scripts
#
# This scripts sets the following:
#   $PASS	Full path to password-store script to test
#   $GPG	Name of gpg executable
#   $KEY{1..5}	GPG key ids of testing keys
#   $TEST_HOME	This folder
#

# shellcheck disable=SC1091,SC2016

# Project directory
TESTS_HOME="$(pwd)"
PROJECT_HOME="$(dirname "$TESTS_HOME")"

# Check dependencies
_die() { echo "${@}" && exit 1; }
PASS="$(command -v pass)"
GPG="$(command -v gpg)"
GIT=true
[[ -e "$PASS" ]] || _die "Could not find pass command"
[[ -e "$GPG" ]] || _die "Could not find gpg command"
if $COVERAGE; then
	KCOV="$(command -v kcov)"
	[[ -e "$KCOV" ]] || _die "Could not find kcov command"
	_pass() {
		"$KCOV" --exclude-line='esac done,clip' \
			--include-path="$PROJECT_HOME/update.bash" --exclude-path=/ \
			"$TMP/$(basename "$0")" "$PASS" "${@}"
	}
else
	_pass() { "$PASS" "${@}"; }
fi

# sharness config
export SHARNESS_TEST_DIRECTORY="$TESTS_HOME"
export SHARNESS_TEST_SRCDIR="$PROJECT_HOME"
source ./lib-sharness/functions.sh
source ./sharness

#  Prepare pass config vars
unset PASSWORD_STORE_DIR
unset PASSWORD_STORE_KEY
unset PASSWORD_STORE_GIT
unset PASSWORD_STORE_GPG_OPTS
unset PASSWORD_STORE_X_SELECTION
unset PASSWORD_STORE_CLIP_TIME
unset PASSWORD_STORE_UMASK
unset PASSWORD_STORE_GENERATED_LENGTH
unset PASSWORD_STORE_CHARACTER_SET
unset PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS
unset PASSWORD_STORE_ENABLE_EXTENSIONS
unset PASSWORD_STORE_EXTENSIONS_DIR
unset PASSWORD_STORE_SIGNING_KEY
unset GNUPGHOME
unset EDITOR

export PASSWORD_STORE_ENABLE_EXTENSIONS=true
export PASSWORD_STORE_EXTENSIONS_DIR="$PROJECT_HOME"

# GnuPG config
unset GPG_AGENT_INFO
export GNUPGHOME="$TESTS_HOME/gnupg/"
export KEY1="D4C78DB7920E1E27F5416B81CC9DB947CF90C77B"
export KEY2="70BD448330ACF0653645B8F2B4DDBFF0D774A374"
export KEY3="62EBE74BE834C2EC71E6414595C4B715EB7D54A8"
export KEY4="9378267629F989A0E96677B7976DD3D6E4691410"
export KEY5="4D2AFBDE67C60F5999D143AFA6E073D439E5020C"
chmod 700 "$GNUPGHOME"

# Predefined passwords to be updated
export PASSWORD="$RANDOM"
export PASSWORD_NUMBERS1="$RANDOM"
export PASSWORD_NUMBERS2="$RANDOM"
export PASSWORD_LETTERS=correcthorsebatterystaple

# Test helpers

pw() {
	local length="${1:-25}" characters="${2:-[:graph:]}"
	bash -c 'read -r -n "$0" pass < <(LC_ALL=C tr -dc "$1" < /dev/urandom) && echo $pass' "$length" "$characters"
}

pass_insert() {
	echo -e "$2\nlogin: $(pw 8 "[:lower:]")\nurl: $(basename "$1")" |
		pass insert --multiline --force "$1" &>/dev/null
}

test_pass_populate() {
	pass init "$KEY1" &>/dev/null
	if $GIT; then
		git config --global user.email "Pass-Automated-Testing-Suite@zx2c4.com" &>/dev/null
		git config --global user.name "Pass Automated Testing Suite" &>/dev/null
		pass git init &>/dev/null
	fi
	pass_insert Business/site.com "$PASSWORD"
	pass_insert Business/site.eu "$PASSWORD"
	pass_insert Business/bitcoin/login "$PASSWORD"
	pass_insert Business/bitcoin/username "$PASSWORD"
	pass_insert 'Business/a space/login' "$PASSWORD"
	pass_insert 'Business/a space/username' "$PASSWORD"
	pass_insert Business/euro/login "$PASSWORD"
	pass_insert Business/euro/username "$PASSWORD"
	pass_insert Email/donenfeld.com "$PASSWORD"
	pass_insert Email/zx2c4.com "$PASSWORD"
	pass_insert France/bank "$PASSWORD"
	pass_insert France/freebox "$PASSWORD"
	pass_insert France/mobilephone "$PASSWORD"
	pass_insert Include/numbers1 "$PASSWORD_NUMBERS1"
	pass_insert Include/numbers2 "$PASSWORD_NUMBERS2"
	pass_insert Include/letters "$PASSWORD_LETTERS"
	pass_insert Exclude/numbers1 "$PASSWORD_NUMBERS1"
	pass_insert Exclude/numbers2 "$PASSWORD_NUMBERS2"
	pass_insert Exclude/letters "$PASSWORD_LETTERS"
}

test_password_is() {
	newpasswd="$(pass show "$1" | head -n 1)"
	[[ "$newpasswd" == "$2" ]]
}

test_password_is_not() {
	newpasswd="$(pass show "$1" | head -n 1)"
	[[ "$newpasswd" != "$2" ]]
}

test_cleanup() {
	rm -rf "$TMP"
	mkdir -p "$TMP"
}

test_export() {
	export testname="$1"
	export PASSWORD_STORE_DIR="$TMP/${testname}-store"
	export PASSWORD_STORE_CLIP_TIME="1"
	export PATH="$TESTS_HOME:$PATH"
	export EDITOR="fake-editor"
	export GIT_DIR="$PASSWORD_STORE_DIR/.git"
	export GIT_WORK_TREE="$PASSWORD_STORE_DIR"
}

test_xclip() {
	echo "$RANDOM" | xclip -i &>/dev/null
	return $?
}

# Check for auxiliary programs
test_xclip && test_set_prereq XCLIP