2022-02-22 20:33:45 +08:00
|
|
|
// Copyright 2022 Memgraph Ltd.
|
2021-10-26 14:53:56 +08:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
|
|
|
// License, and you may not use this file except in compliance with the Business Source License.
|
|
|
|
//
|
|
|
|
// As of the Change Date specified in that file, in accordance with
|
|
|
|
// the Business Source License, use of this software will be governed
|
|
|
|
// by the Apache License, Version 2.0, included in the file
|
|
|
|
// licenses/APL.txt.
|
|
|
|
|
2018-08-22 16:59:46 +08:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
|
|
|
#include "communication/bolt/client.hpp"
|
|
|
|
#include "io/network/endpoint.hpp"
|
|
|
|
#include "io/network/utils.hpp"
|
|
|
|
|
|
|
|
DEFINE_string(address, "127.0.0.1", "Server address");
|
|
|
|
DEFINE_int32(port, 7687, "Server port");
|
|
|
|
DEFINE_string(username, "admin", "Username for the database");
|
|
|
|
DEFINE_string(password, "admin", "Password for the database");
|
|
|
|
DEFINE_bool(use_ssl, false, "Set to true to connect with SSL to the server.");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies that user 'user' has privileges that are given as positional
|
|
|
|
* arguments.
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::communication::SSLInit sslInit;
|
2018-08-22 16:59:46 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::io::network::Endpoint endpoint(memgraph::io::network::ResolveHostname(FLAGS_address), FLAGS_port);
|
2018-08-22 16:59:46 +08:00
|
|
|
|
2022-02-22 20:33:45 +08:00
|
|
|
memgraph::communication::ClientContext context(FLAGS_use_ssl);
|
2022-08-26 19:19:27 +08:00
|
|
|
memgraph::communication::bolt::Client client(context);
|
2018-08-22 16:59:46 +08:00
|
|
|
|
2018-10-19 18:28:38 +08:00
|
|
|
client.Connect(endpoint, FLAGS_username, FLAGS_password);
|
2018-08-22 16:59:46 +08:00
|
|
|
|
|
|
|
try {
|
2018-08-29 15:18:51 +08:00
|
|
|
auto ret = client.Execute("SHOW PRIVILEGES FOR user", {});
|
2018-08-22 16:59:46 +08:00
|
|
|
const auto &records = ret.records;
|
|
|
|
uint64_t count_got = 0;
|
|
|
|
for (const auto &record : records) {
|
|
|
|
count_got += record.size();
|
|
|
|
}
|
|
|
|
if (count_got != argc - 1) {
|
2021-02-18 22:32:43 +08:00
|
|
|
LOG_FATAL("Expected the grants to have {} entries but they had {} entries!", argc - 1, count_got);
|
2018-08-22 16:59:46 +08:00
|
|
|
}
|
|
|
|
uint64_t pos = 1;
|
|
|
|
for (const auto &record : records) {
|
|
|
|
for (const auto &value : record) {
|
|
|
|
std::string expected(argv[pos++]);
|
|
|
|
if (value.ValueString() != expected) {
|
2021-02-18 22:32:43 +08:00
|
|
|
LOG_FATAL("Expected to get the value '{} but got the value '{}'", expected, value.ValueString());
|
2018-08-22 16:59:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 20:33:45 +08:00
|
|
|
} catch (const memgraph::communication::bolt::ClientQueryException &e) {
|
2021-01-21 22:47:56 +08:00
|
|
|
LOG_FATAL(
|
|
|
|
"The query shoudn't have failed but it failed with an "
|
|
|
|
"error message '{}'",
|
|
|
|
e.what());
|
2018-08-22 16:59:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|