背景
下位10%のダメなエンジニアにだけ解けないパズルを解いた結果、下位10%のダメなエンジニアだと判明した - Qiita の続編です。
自分ルール
(極力)ググらない。
過去の自分の投稿記事は、参照OK。
解答
$ curl http://challenge-your-limits2.herokuapp.com/something/something
{"error":"Yo, this is just an example. Go back and 'call/my/APIs'"}
これは例なので、call/my/APIs
に変更してほしいみたいです。
$ curl http://challenge-your-limits2.herokuapp.com/call/my/APIs
{"error":"Ok. Let's get started! End Point is correct. But HTTP Method should be..."}
ここがスタートラインのようです。
HTTPではメソッドではダメらしいので、HTTPSにしてみます。
$ curl -x POST https://challenge-your-limits2.herokuapp.com/call/my/APIs
0curl: (5) Could not resolve proxy: POST
プロキシのエラーが出てしまいました。
どうやら前回とは異なり、HTTPSで叩くのは違うみたいです。
ここでハマって、やけくそでPUTで叩いたときにメッセージが変わりました。
$ curl -X PUT http://challenge-your-limits2.herokuapp.com/call/my/APIs
{"error":"Very close. Keep trying. As I said, End Point is correct"}
いいよ~ここままやり続けよう!
みたいなメッセージが返ってきました。
というわけで、DELETEをやってみました。
$ curl -X DELETE http://challenge-your-limits2.herokuapp.com/call/my/APIs
{"message":"Well done! haha! Surprised? Yeah, the answer was DELETE. Ok. Next === /c2_users/:id/hacker_apply"}
なぜかはわかりませんが、「よくやった!はは!驚いたでしょ??答えはDELETEでした!!!」みたいなアメリカン風なメッセージが返ってきました。
(めっちゃバカにされている??)
次は/c2_users/:id/hacker_apply
とのことなので、とりあえず実行。
$ curl http://challenge-your-limits2.herokuapp.com/c2_users/:id/hacker_apply
{"error":"Please authenticate using Basic Auth with your username and password. You want a clue? Shout out 'help/me/out'"}
ユーザ名とパスワードを認証してきて。ヒントが欲しいならhelp/me/out
らしいので、これもとりあえず実行。
$ curl http://challenge-your-limits2.herokuapp.com/help/me/out
{"message":"By the way, Have you already registered? This is the clue only for REGISTERED user. You should have your id before you check the clue. If you don't, go to /c2_users/ and register. Hey, Registered users! Here you go. === bit.ly/1T8gVdG === You don't know about 'bit.ly'? Google it!"}
bit.ly/1T8gVdG
をgoogle検索すればcurlのベーシック認証のやり方が記載されたページに遷移します。
どうやらcurlのベーシック認証をする必要があるようです。
$ curl -X POST -d 'username=hoge' http://challenge-your-limits2.herokuapp.com/c2_users/
{"error":"Validation Error - [:email, \"can't be blank\"]"}
どうやらusernameとemailがパラメータとして必要なようです。
$ curl -X POST -d 'username=hoge&email=qwertyuio@fuga.com' http://challenge-your-limits2.herokuapp.com/c2_users/
{"id":3216,"username":"hoge","email":"qwertyuio@fuga.com","password":"zL90Vrae7jnTkbQm","comment":null,"created_at":"2018-12-28T00:07:14.514Z","updated_at":"2018-12-28T00:07:14.514Z"}
idとpasswordが発行されて返ってきました。
あとは、これを使ってベーシック認証します。
$ curl -u hoge:zL90Vrae7jnTkbQm http://challenge-your-limits2.herokuapp.com/c2_users/3216/hacker_apply
{"message":"Awesome! Can you come over here? === XXXXX You want a clue? Shout out 'give me a clue'"}
ここに来てくれませんか??と言われている文字列をBase64デコードします。
Base64のデコード - オンラインBase64のデコーダ
そうすると、
Good job!! Please access to the url from your web browser. === \
http://challenge-your-limits2.herokuapp.com/winner_comments/XXXXXXXXXX
URLが表示されて、そこにブラウザでアクセスすれば終わりです。
終わりに
前回の知識もあってか、結構スムーズに解けました。
最後のBase64デコードにハマり、ググりまくりました。
Basic認証では、ユーザ名とパスワードの組みをコロン ":" でつなぎ、Base64でエンコードして送信する。このため、盗聴や改竄が簡単であるという欠点を持つが、ほぼ全てのWebサーバおよびブラウザで対応しているため、広く使われている。
ということを学びました。(小並感)
参考文献
【パズル2】ほとんどのエンジニアには解けるが、下位20%のダメなエンジニアにだけ解けないパズル? - ベルリンのITスタートアップで働くジャバ・ザ・ハットリの日記