mirror of
https://codeberg.org/scip/dbtool.git
synced 2025-12-16 19:00:58 +01:00
unitfixes (#3)
- fix regex match padding - fix key copying - add more unit tests
This commit is contained in:
@@ -44,9 +44,17 @@ steps:
|
|||||||
# check modified key
|
# check modified key
|
||||||
- build/dbtool -d test.db -s -k test | grep modified
|
- build/dbtool -d test.db -s -k test | grep modified
|
||||||
# use splitting with regex
|
# use splitting with regex
|
||||||
- printf "today:100\nyesterday:500\n" | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
|
- echo today:100 | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
|
||||||
# check if it works
|
# check if it works
|
||||||
- cat /etc/passwd | build/dbtool -d test.db -s -k today | grep 100
|
- build/dbtool -d test.db -s -k today | grep 100
|
||||||
|
# use splitting with regex reverse
|
||||||
|
- echo today:cold | build/dbtool -d test.db -R -i -f -t '^([^:]*):([^:]*)'
|
||||||
|
# check if it works
|
||||||
|
- build/dbtool -d test.db -s -k cold | grep today
|
||||||
|
# check encryption
|
||||||
|
- build/dbtool -d test.db -i -k borg -v sevenofnine -p -P foobar
|
||||||
|
- build/dbtool -d test.db -s -k borg -p -P foobar | grep sevenofnine
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
build-gdbm:
|
build-gdbm:
|
||||||
@@ -90,7 +98,14 @@ steps:
|
|||||||
# check modified key
|
# check modified key
|
||||||
- build/dbtool -d test.db -s -k test | grep modified
|
- build/dbtool -d test.db -s -k test | grep modified
|
||||||
# use splitting with regex
|
# use splitting with regex
|
||||||
- printf "today:100\nyesterday:500\n" | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
|
- echo today:100 | build/dbtool -d test.db -i -f -t '^([^:]*):([^:]*)'
|
||||||
# check if it works
|
# check if it works
|
||||||
- cat /etc/passwd | build/dbtool -d test.db -s -k today | grep 100
|
- build/dbtool -d test.db -s -k today | grep 100
|
||||||
|
# use splitting with regex reverse
|
||||||
|
- echo today:cold | build/dbtool -d test.db -R -i -f -t '^([^:]*):([^:]*)'
|
||||||
|
# check if it works
|
||||||
|
- build/dbtool -d test.db -s -k cold | grep today
|
||||||
|
# check encryption
|
||||||
|
- build/dbtool -d test.db -i -k borg -v sevenofnine -p -P foobar
|
||||||
|
- build/dbtool -d test.db -s -k borg -p -P foobar | grep sevenofnine
|
||||||
|
|
||||||
|
|||||||
19
.woodpecker/test.sh
Executable file
19
.woodpecker/test.sh
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
yq '.steps.test-gdbm.commands' < .woodpecker/build.yaml \
|
||||||
|
| grep -- - | grep -v apk | sed 's/^\- //' \
|
||||||
|
| while read COMMAND; do
|
||||||
|
echo "$COMMAND" | bash -e > debug.log 2>&1
|
||||||
|
if test $? -ne 0; then
|
||||||
|
echo "fail - $COMMAND"
|
||||||
|
if test -s debug.log; then
|
||||||
|
cat debug.log
|
||||||
|
else
|
||||||
|
echo exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ok - $COMMAND"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -f debug.log
|
||||||
22
Makefile
Normal file
22
Makefile
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#
|
||||||
|
# convenience wrapper around meson and ninja. Forgive me, I'm old :
|
||||||
|
|
||||||
|
.PHONY: all static install test clean debug
|
||||||
|
all:
|
||||||
|
meson setup --reconfigure build
|
||||||
|
ninja -C build
|
||||||
|
|
||||||
|
install: all
|
||||||
|
sudo ninja -C install
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build dbtool*core* dbtool.1 test.db
|
||||||
|
|
||||||
|
test:
|
||||||
|
@.woodpecker/test.sh
|
||||||
|
|
||||||
|
debug: all
|
||||||
|
rm -f test.db
|
||||||
|
build/dbtool -d test.db -i -k borg -v sevenofnine -p -P foobar
|
||||||
|
build/dbtool -d test.db -s -k borg -p -P foobar
|
||||||
|
|
||||||
@@ -57,10 +57,7 @@ void cipher::init(const string& phrase) {
|
|||||||
dig.putDigest( (unsigned char *)phrase.c_str(), phrase.length() );
|
dig.putDigest( (unsigned char *)phrase.c_str(), phrase.length() );
|
||||||
__key = dig.stringDigest(); // this is a 32 byte long string, as Rijndael:: expects
|
__key = dig.stringDigest(); // this is a 32 byte long string, as Rijndael:: expects
|
||||||
|
|
||||||
/* convert the key to unsigned char[] */
|
memcpy(key, __key, 32);
|
||||||
for(int i=0; i<32; i++) {
|
|
||||||
key[i] = __key[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
cipher.h
1
cipher.h
@@ -61,7 +61,6 @@ class cipher {
|
|||||||
Rijndael rijn;
|
Rijndael rijn;
|
||||||
MD5Digest dig;
|
MD5Digest dig;
|
||||||
unsigned char key[32];
|
unsigned char key[32];
|
||||||
string blah;
|
|
||||||
const char* error(int num);
|
const char* error(int num);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
23
dbtool.cc
23
dbtool.cc
@@ -67,8 +67,8 @@ int main(int argc, char *argv[]) {
|
|||||||
case 'i':
|
case 'i':
|
||||||
/* insert */
|
/* insert */
|
||||||
if(config.key == "") {
|
if(config.key == "") {
|
||||||
cerr << pkg << ": key required\n";
|
cerr << pkg << ": key required\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
engine.insert();
|
engine.insert();
|
||||||
break;
|
break;
|
||||||
@@ -82,32 +82,32 @@ int main(int argc, char *argv[]) {
|
|||||||
case 's':
|
case 's':
|
||||||
/* select */
|
/* select */
|
||||||
if(config.key == "") {
|
if(config.key == "") {
|
||||||
cerr << pkg << ": key required\n";
|
cerr << pkg << ": key required\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
engine.select();
|
engine.select();
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
/* regexp select */
|
/* regexp select */
|
||||||
if(config.key == "") {
|
if(config.key == "") {
|
||||||
cerr << pkg << ": key (regexp) required\n";
|
cerr << pkg << ": key (regexp) required\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
engine.regexp();
|
engine.regexp();
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
/* remove */
|
/* remove */
|
||||||
if(config.key == "") {
|
if(config.key == "") {
|
||||||
cerr << pkg << ": key required\n";
|
cerr << pkg << ": key required\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
engine.remove();
|
engine.remove();
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
/* update */
|
/* update */
|
||||||
if(config.key == "") {
|
if(config.key == "") {
|
||||||
cerr << pkg << ": key required\n";
|
cerr << pkg << ": key required\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
engine.update();
|
engine.update();
|
||||||
break;
|
break;
|
||||||
@@ -125,7 +125,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string readpass() {
|
string readpass() {
|
||||||
char *envpass;
|
char *envpass;
|
||||||
envpass = getenv(PW_VARNAME);
|
envpass = getenv(PW_VARNAME);
|
||||||
@@ -146,5 +145,3 @@ string readpass() {
|
|||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -334,6 +334,7 @@ void Engine::regexp() {
|
|||||||
|
|
||||||
char *part = (char *)malloc(substring_length+1);
|
char *part = (char *)malloc(substring_length+1);
|
||||||
part = strncpy(part, (char *)substring_start, substring_length);
|
part = strncpy(part, (char *)substring_start, substring_length);
|
||||||
|
part[substring_length] = '\0';
|
||||||
|
|
||||||
subs[i-1] = part;
|
subs[i-1] = part;
|
||||||
free(part);
|
free(part);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ project(
|
|||||||
'dbtool',
|
'dbtool',
|
||||||
'cpp',
|
'cpp',
|
||||||
license: 'GPL',
|
license: 'GPL',
|
||||||
version: '1.9.2',
|
version: '1.9.3',
|
||||||
meson_version: '>=1.3',
|
meson_version: '>=1.3',
|
||||||
default_options: [
|
default_options: [
|
||||||
'warning_level=2',
|
'warning_level=2',
|
||||||
|
|||||||
Reference in New Issue
Block a user