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

v0.6.0 #71

Merged
merged 15 commits into from
Sep 5, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/crystal_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Crystal Build

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/crystal_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Crystal Lint

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/crystal_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Crystal Test

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "dev" ]

jobs:
build:
Expand Down
17 changes: 11 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## ❤️ Contribute
1. Write code in forked repo
2. Make Pull Request to `dev` branch
3. Finish :D

![](https://github.com/hahwul/noir/assets/13212227/23989dab-6b4d-4f18-904f-7f5cfd172b04)

## 🛠️ How to Build and Test?
### Clone and Install Dependencies
```bash
Expand Down Expand Up @@ -30,16 +37,14 @@ ameba --fix
# https://github.com/crystal-ameba/ameba#installation
```

## ❤️ Contribute
1. Write code in forked repo
2. Make Pull Request
3. Finish :D

## 🧭 Code structure
- spec: unit-test codes
- spec (for `crystal spec`)
- unit_test: unit-test codes
- functional_test: functional test codes
- src
- analyzer: Code analyzers for Endpoint URL and Parameter analysis
- detector: Codes for language, framework identification
- models: Everything for the model, such as class, structure, etc
- utils: Utility codes
- etc...
- noir.cr: main and command-line parser
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

| Language | Framework | URL | Method | Param | Header | WS |
|----------|-----------|-----|--------|-------|--------|----|
| Go | Echo | ✅ | ✅ | ✅ | X | X |
| Go | Echo | ✅ | ✅ | ✅ | ✅ | X |
| Go | Gin | ✅ | ✅ | ✅ | ✅ | X |
| Python | Django | ✅ | X | X | X | X |
| Python | Flask | ✅ | X | X | X | X |
| Ruby | Rails | ✅ | ✅ | ✅ | ✅ | X |
| Ruby | Sinatra | ✅ | ✅ | ✅ | ✅ | X |
| Php | | ✅ | ✅ | ✅ | ✅ | X |
| Java | Spring | ✅ | ✅ | X | X | X |
| Java | Jsp | X | X | X | X | X |
| Java | Jsp | | | | X | X |
| Crystal | Kemal | ✅ | ✅ | ✅ | ✅ | ✅ |
| JS | Express | ✅ | ✅ | X | X | X |
| JS | Next | X | X | X | X | X |
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: noir
version: 0.5.4
version: 0.6.0

authors:
- hahwul <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions spec/functional_test/fixtures/go_echo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func main() {
})
e.GET("/pet", func(c echo.Context) error {
_ = c.QueryParam("query")
_ = c.Request().Header.Get("X-API-Key")
return c.String(http.StatusOK, "Hello, Pet!")
})
e.POST("/pet", func(c echo.Context) error {
Expand Down
32 changes: 32 additions & 0 deletions spec/functional_test/fixtures/go_gin/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module github.com/hahwul/test-go-app

go 1.20

require (
github.com/bytedance/sonic v1.10.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Empty file.
29 changes: 29 additions & 0 deletions spec/functional_test/fixtures/go_gin/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"net/http"

"github.com/gin-gonic/gin"
)

func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
_ = c.DefaultQuery("name", "Guest")
_ = c.Query("age")

c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
r.POST("/submit", func(c *gin.Context) {
username := c.PostForm("username")
password := c.DefaultPostForm("password", "default_password")
userAgent := c.GetHeader("User-Agent")

c.String(http.StatusOK, "Submitted data: Username=%s, Password=%s, userAgent=%s", username, password, userAgent)
})

r.Static("/public", "public")
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
3 changes: 3 additions & 0 deletions spec/functional_test/fixtures/jsp/el.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%
String username = ${param.username}
%>
4 changes: 4 additions & 0 deletions spec/functional_test/fixtures/jsp/get_param.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
%>
34 changes: 34 additions & 0 deletions spec/functional_test/fixtures/raml/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#%RAML 1.0
title: User API
version: v1

/users/{userId}:
get:
description: Retrieve user information
queryParameters:
userId:
description: The ID of the user to retrieve
type: integer
example: 123
headers:
Authorization:
description: API key or token for authentication
type: string
example: Bearer my_api_token
responses:
200:
description: User information retrieved successfully

/users:
post:
description: Create a new user
body:
application/json:
example:
{
"name": "John Doe",
"email": "[email protected]"
}
responses:
201:
description: User created successfully
1 change: 1 addition & 0 deletions spec/functional_test/testers/go_echo_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extected_endpoints = [
Endpoint.new("/", "GET"),
Endpoint.new("/pet", "GET", [
Param.new("query", "", "query"),
Param.new("X-API-Key", "", "header"),
]),
Endpoint.new("/pet", "POST", [
Param.new("name", "", "json"),
Expand Down
18 changes: 18 additions & 0 deletions spec/functional_test/testers/go_gin_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "../func_spec.cr"

extected_endpoints = [
Endpoint.new("/ping", "GET", [
Param.new("name", "", "query"),
Param.new("age", "", "query"),
]),
Endpoint.new("/submit", "POST", [
Param.new("username", "", "form"),
Param.new("password", "", "form"),
Param.new("User-Agent", "", "header"),
]),
]

FunctionalTester.new("fixtures/go_gin/", {
:techs => 1,
:endpoints => 2,
}, extected_endpoints).test_all
14 changes: 14 additions & 0 deletions spec/functional_test/testers/jsp_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "../func_spec.cr"

extected_endpoints = [
Endpoint.new("/get_param.jsp", "GET", [
Param.new("username", "", "query"),
Param.new("password", "", "query"),
]),
Endpoint.new("/el.jsp", "GET", [Param.new("username", "", "query")]),
]

FunctionalTester.new("fixtures/jsp/", {
:techs => 1,
:endpoints => 2,
}, extected_endpoints).test_all
17 changes: 17 additions & 0 deletions spec/functional_test/testers/raml_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "../func_spec.cr"

extected_endpoints = [
Endpoint.new("/users/{userId}", "GET", [
Param.new("userId", "", "query"),
Param.new("Authorization", "", "header"),
]),
Endpoint.new("/users", "POST", [
Param.new("name", "", "json"),
Param.new("email", "", "json"),
]),
]

FunctionalTester.new("fixtures/raml/", {
:techs => 1,
:endpoints => 2,
}, extected_endpoints).test_all
3 changes: 3 additions & 0 deletions src/analyzer/analyzer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ def initialize_analyzers(logger : NoirLogger)
analyzers["java_spring"] = ->analyzer_spring(Hash(Symbol, String))
analyzers["php_pure"] = ->analyzer_php_pure(Hash(Symbol, String))
analyzers["go_echo"] = ->analyzer_go_echo(Hash(Symbol, String))
analyzers["go_gin"] = ->analyzer_go_gin(Hash(Symbol, String))
analyzers["python_flask"] = ->analyzer_flask(Hash(Symbol, String))
analyzers["python_django"] = ->analyzer_django(Hash(Symbol, String))
analyzers["js_express"] = ->analyzer_express(Hash(Symbol, String))
analyzers["crystal_kemal"] = ->analyzer_kemal(Hash(Symbol, String))
analyzers["oas2"] = ->analyzer_oas2(Hash(Symbol, String))
analyzers["oas3"] = ->analyzer_oas3(Hash(Symbol, String))
analyzers["raml"] = ->analyzer_raml(Hash(Symbol, String))
analyzers["java_jsp"] = ->analyzer_jsp(Hash(Symbol, String))

logger.info_sub "#{analyzers.size} Analyzers initialized"
logger.debug "Analyzers:"
Expand Down
8 changes: 8 additions & 0 deletions src/analyzer/analyzers/analyzer_go_echo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class AnalyzerGoEcho < Analyzer
end
end
end

if line.includes?("Request().Header.Get(")
match = line.match(/Request\(\)\.Header\.Get\(\"(.*)\"\)/)
if match
header_name = match[1]
last_endpoint.params << Param.new(header_name, "", "header")
end
end
end
end
end
Expand Down
Loading
Loading