Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /token endpoint for authentication for testcode #269

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions spec/functional_test/fixtures/crystal_kemal/src/testapp.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ post "/query" do
env.params.body["query"].as(String)
end

get "/token" do
env.params.body["client_id"].as(String)
env.params.body["redirect_url"].as(String)
env.params.body["grant_type"].as(String)
end

ws "/socket" do |socket|
socket.send "Hello from Kemal!"
end
Expand Down
7 changes: 6 additions & 1 deletion spec/functional_test/testers/crystal_kemal_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ extected_endpoints = [
Param.new("query", "", "form"),
Param.new("my_auth", "", "cookie"),
]),
Endpoint.new("/token", "GET", [
Param.new("grant_type", "", "form"),
Param.new("redirect_url", "", "form"),
Param.new("client_id", "", "form"),
]),
Endpoint.new("/1.html", "GET"),
Endpoint.new("/2.html", "GET"),
]

FunctionalTester.new("fixtures/crystal_kemal/", {
:techs => 1,
:endpoints => 5,
:endpoints => 6,
}, extected_endpoints).test_all
9 changes: 7 additions & 2 deletions src/output_builder/common.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ class OutputBuilderCommon < OutputBuilder
r_buffer += "\n ○ body: #{r_body}"
end

if baked[:tags].size > 0
r_tags = baked[:tags].join(" ").colorize(:light_magenta).toggle(@is_color)
tags = baked[:tags]
endpoint.tags.each do |tag|
tags << tag.name.to_s
end

if tags.size > 0
r_tags = tags.join(" ").colorize(:light_magenta).toggle(@is_color)
r_buffer += "\n ○ tags: #{r_tags}"
end

Expand Down
8 changes: 6 additions & 2 deletions src/tagger/taggers/oauth.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "../../models/tagger"
require "../../models/endpoint"

class OAuthTagger < Tagger
WORDS = ["grant_type", "code", "redirect_uri", "client_id", "client_secret"]
WORDS = ["grant_type", "code", "redirect_uri", "redirect_url", "client_id", "client_secret"]

def initialize(options : Hash(Symbol, String))
super
Expand All @@ -17,8 +17,12 @@ class OAuthTagger < Tagger
tmp_params.push param.name.to_s
end

words_set = Set.new(WORDS)
tmp_params_set = Set.new(tmp_params)
intersection = words_set & tmp_params_set

# Check that at least three parameters match.
check = (WORDS & tmp_params).size >= 3
check = intersection.size.to_i >= 3

if check
tag = Tag.new("oauth", "Suspected OAuth endpoint for granting 3rd party access.", "Oauth")
Expand Down
Loading