Skip to content

Commit

Permalink
Merge pull request #269 from noir-cr/improve-test-code
Browse files Browse the repository at this point in the history
Add /token endpoint for authentication for testcode
  • Loading branch information
hahwul authored Mar 29, 2024
2 parents 3969584 + 27b1b5f commit ff6d794
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
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

0 comments on commit ff6d794

Please sign in to comment.