• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 27660975269

17 Jun 2026 02:06AM UTC coverage: 57.452% (-0.03%) from 57.477%
27660975269

Pull #1551

github

web-flow
Merge 1c61e7f1d into 4da97561f
Pull Request #1551: refactor(pass): inject AppSettings into Pass hierarchy (PR A of #1511)

44 of 84 new or added lines in 4 files covered. (52.38%)

13 existing lines in 6 files now uncovered.

3982 of 6931 relevant lines covered (57.45%)

23.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.41
/src/realpass.cpp
1
// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "realpass.h"
4
#include "debughelper.h"
5
#include "util.h"
6

7
#include <QDir>
8
#include <QFileInfo>
9
#include <QRegularExpression>
10
#include <utility>
11

12
using Enums::GIT_INIT;
13
using Enums::GIT_PULL;
14
using Enums::GIT_PUSH;
15
using Enums::PASS_COPY;
16
using Enums::PASS_GREP;
17
using Enums::PASS_INIT;
18
using Enums::PASS_INSERT;
19
using Enums::PASS_MOVE;
20
using Enums::PASS_OTP_GENERATE;
21
using Enums::PASS_REMOVE;
22
using Enums::PASS_SHOW;
23

24
RealPass::RealPass() = default;
1✔
25

26
/**
27
 * @brief RealPass::GitInit pass git init wrapper
28
 */
29
void RealPass::GitInit() { executePass(GIT_INIT, {"git", "init"}); }
×
30

31
/**
32
 * @brief RealPass::GitInit pass git pull wrapper which blocks until process
33
 *                          finishes
34
 */
35
void RealPass::GitPull_b() {
×
36
  int result =
NEW
37
      Executor::executeBlocking(m_settings.passExecutable, {"git", "pull"});
×
38
  if (result != 0) {
39
#ifdef QT_DEBUG
40
    dbg() << "Git pull failed with code:" << result;
41
#endif
42
  }
43
}
×
44

45
/**
46
 * @brief RealPass::GitPull pass git pull wrapper
47
 */
48
void RealPass::GitPull() { executePass(GIT_PULL, {"git", "pull"}); }
×
49

50
/**
51
 * @brief RealPass::GitPush pass git push wrapper
52
 */
53
void RealPass::GitPush() { executePass(GIT_PUSH, {"git", "push"}); }
×
54

55
/**
56
 * @brief RealPass::Show pass show
57
 *
58
 * @param file      file to decrypt
59
 *
60
 * @return  if block is set, returns exit status of internal decryption
61
 * process
62
 *          otherwise returns QProcess::NormalExit
63
 */
64
void RealPass::Show(QString file) {
×
65
  executePass(PASS_SHOW, {"show", file}, "", true);
×
66
}
×
67

68
/**
69
 * @brief RealPass::OtpGenerate pass otp
70
 * @param file      file containing OTP uri
71
 */
72
void RealPass::OtpGenerate(QString file) {
×
73
  executePass(PASS_OTP_GENERATE, {"otp", file}, "", true);
×
74
}
×
75

76
/**
77
 * @brief RealPass::Insert pass insert
78
 */
79
void RealPass::Insert(QString file, QString newValue, bool overwrite) {
×
80
  QStringList args = {"insert", "-m"};
×
81
  if (overwrite) {
×
82
    args.append("-f");
×
83
  }
84
  args.append(file);
85
  executePass(PASS_INSERT, args, newValue);
×
86
}
×
87

88
/**
89
 * @brief RealPass::Remove pass remove wrapper
90
 */
91
void RealPass::Remove(QString file, bool isDir) {
×
92
  executePass(PASS_REMOVE, {"rm", (isDir ? "-rf" : "-f"), file});
×
93
}
×
94

95
/**
96
 * @brief RealPass::Init initialize pass repository
97
 *
98
 * @param path  Absolute path to new password-store
99
 * @param users list of users with ability to decrypt new password-store
100
 */
101
void RealPass::Init(QString path, const QList<UserInfo> &users) {
×
102
  // remove the passStore directory otherwise,
103
  // pass would create a passStore/passStore/dir
104
  // but you want passStore/dir
NEW
105
  QString normalizedPath = QDir::cleanPath(path);
×
NEW
106
  QString normalizedStore = QDir::cleanPath(m_settings.passStore);
×
NEW
107
  QString dirWithoutPassdir;
×
NEW
108
  if (normalizedPath.startsWith(normalizedStore)) {
×
NEW
109
    dirWithoutPassdir = normalizedPath.mid(normalizedStore.size());
×
NEW
110
    if (dirWithoutPassdir.startsWith('/')) {
×
NEW
111
      dirWithoutPassdir.remove(0, 1);
×
112
    }
113
  } else {
NEW
114
    dirWithoutPassdir = normalizedPath;
×
115
  }
116
  QStringList args = {"init", "--path=" + dirWithoutPassdir};
×
117
  foreach (const UserInfo &user, users) {
×
118
    if (user.enabled) {
×
119
      args.append(user.key_id);
×
120
    }
121
  }
122
  executePass(PASS_INIT, args);
×
123
}
×
124

125
/**
126
 * @brief RealPass::Move move a file (or folder)
127
 * @param src source file or folder
128
 * @param dest destination file or folder
129
 * @param force overwrite
130
 */
131
void RealPass::Move(const QString src, const QString dest, const bool force) {
×
132
  passMoveOrCopy(PASS_MOVE, QStringLiteral("mv"), src, dest, force);
×
133
}
×
134

135
/**
136
 * @brief RealPass::Copy copy a file (or folder)
137
 * @param src source file or folder
138
 * @param dest destination file or folder
139
 * @param force overwrite
140
 */
141
void RealPass::Copy(const QString src, const QString dest, const bool force) {
×
142
  passMoveOrCopy(PASS_COPY, QStringLiteral("cp"), src, dest, force);
×
143
}
×
144

145
/**
146
 * @brief RealPass::passMoveOrCopy shared `pass mv` / `pass cp` implementation.
147
 * @param id PASS_MOVE or PASS_COPY.
148
 * @param subcommand "mv" or "cp".
149
 * @param src source file or folder.
150
 * @param dest destination file or folder.
151
 * @param force overwrite.
152
 */
153
void RealPass::passMoveOrCopy(PROCESS id, const QString &subcommand,
×
154
                              const QString &src, const QString &dest,
155
                              const bool force) {
156
  QFileInfo srcFileInfo = QFileInfo(src);
×
157
  QFileInfo destFileInfo = QFileInfo(dest);
×
158

159
  // force mode?
160
  // pass uses always the force mode, when call from eg. QT. so we have to
161
  // check if this are to files and the user didn't want to move force
162
  if (!force && srcFileInfo.isFile() && destFileInfo.isFile()) {
×
163
    return;
164
  }
165

NEW
166
  QString normalizedStore = QDir::cleanPath(m_settings.passStore);
×
NEW
167
  QString normalizedSrc = QDir::cleanPath(QDir(src).absolutePath());
×
NEW
168
  QString normalizedDest = QDir::cleanPath(QDir(dest).absolutePath());
×
169

NEW
170
  QString passSrc = QDir(normalizedStore).relativeFilePath(normalizedSrc);
×
NEW
171
  QString passDest = QDir(normalizedStore).relativeFilePath(normalizedDest);
×
172

173
  // remove the .gpg because pass will not work
174
  if (srcFileInfo.isFile() && srcFileInfo.suffix() == "gpg") {
×
175
    passSrc.replace(Util::endsWithGpg(), "");
×
176
  }
177
  if (destFileInfo.isFile() && destFileInfo.suffix() == "gpg") {
×
178
    passDest.replace(Util::endsWithGpg(), "");
×
179
  }
180

181
  QStringList args;
×
182
  args << subcommand;
183
  if (force) {
×
184
    args << "-f";
×
185
  }
186
  args << passSrc;
187
  args << passDest;
188
  executePass(id, args);
×
189
}
×
190

191
/**
192
 * @brief Search all password content via 'pass grep'.
193
 *
194
 * The pattern is interpreted by `pass grep` (GNU grep, **POSIX BRE**), which
195
 * differs from the PCRE dialect used by the native backend — see
196
 * Pass::Grep for the cross-backend caveat.
197
 * @param pattern Search pattern (POSIX BRE).
198
 * @param caseInsensitive true for case-insensitive search.
199
 */
200
void RealPass::Grep(QString pattern, bool caseInsensitive) {
×
201
  QStringList args = {"grep"};
×
202
  if (caseInsensitive)
×
203
    args << "-i";
×
204
  args << "--" << pattern;
×
205
  executePass(PASS_GREP, args, QString(), true);
×
206
}
×
207

208
/**
209
 * @brief Wrapper for executing pass commands.
210
 * @param id Process identifier for this operation
211
 * @param args Command-line arguments for pass
212
 * @param input Input to pass to the process (typically empty)
213
 * @param readStdout Whether to capture standard output
214
 * @param readStderr Whether to capture standard error output
215
 */
216
void RealPass::executePass(PROCESS id, const QStringList &args, QString input,
×
217
                           bool readStdout, bool readStderr) {
NEW
218
  executeWrapper(id, m_settings.passExecutable, args, std::move(input),
×
219
                 readStdout, readStderr);
UNCOV
220
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc