1#include <stdio.h>
2#include <stdlib.h>
3#include <string>
4#include <iostream>
5
6/*
7Premise:
8
9We have a top secret file that only authorized users are allowed to download, and they need a CLI tool for retrieving it.
10We tasked a developer with building the server and client for this.
11He built the client first, and has sent you his code for review.
12
13What feedback, questions, or concerns would you give the developer after reviewing his client.
14
15*/
16bool userIsFound(std::string query)
17{
18 // Pretend this method actually executes an SQL query instead of always returning true
19 return true;
20}
21
22void fetchHttpFile(std::string url)
23{
24 // Pretend the code for this lives somewhere else
25}
26
27int main (int argc, char* argv[])
28{
29 char username[20];
30 char password[20];
31 strcpy(username, argv[1]);
32 strcpy(password, argv[2]);
33
34 std::string query = "SELECT * FROM users WHERE username=" + std::string(username) + " AND password=" + std::string(password);
35 std::string url = "http://secretuser:secretpassword@www.example.com/secretfile";
36
37 if (userIsFound(query)) {
38 fetchHttpFile(url);
39 std::cout << "Downloading file: " + url;
40 exit (EXIT_SUCCESS);
41 }
42 else
43 {
44 std::cout << "Error downloading file: " + url + " You do not have permission.";
45 exit (EXIT_FAILURE);
46 }
47}