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

Feature/horusec-csharp #131

Merged
merged 87 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
4bbe12f
Adding base horusec csharp cli
nathanmartinszup Nov 13, 2020
4cab315
Adding csharp rules structure
nathanmartinszup Nov 13, 2020
89a901e
Fixing security hashes
wiliansilvazup Nov 13, 2020
45a3a03
Adding horusec csharp cli injetion rules
nathanmartinszup Nov 13, 2020
2bb7841
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
nathanmartinszup Nov 13, 2020
785218a
Adding others rules
wiliansilvazup Nov 13, 2020
026b637
Adding sql injection linq rule
nathanmartinszup Nov 13, 2020
583eacd
Update leaks with set pwd
wiliansilvazup Nov 13, 2020
0f4cf50
Updating branch and fixing some errors
nathanmartinszup Nov 13, 2020
02437f9
Fixing conflicts
wiliansilvazup Nov 16, 2020
b60ec8c
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 16, 2020
d857a33
Update make file and adding pipeline of horusec-csharp
wiliansilvazup Nov 16, 2020
8438669
Adding password validation
wiliansilvazup Nov 16, 2020
642c01c
Adding sql injection rules in csharp cli
nathanmartinszup Nov 16, 2020
36ba260
Updating branch with origin, fixing conflicts and some errors
nathanmartinszup Nov 16, 2020
a1beb6f
Adding rules of cookies, view state
wiliansilvazup Nov 16, 2020
2cb8a96
Merge
wiliansilvazup Nov 16, 2020
ecedf7b
Fixing errors
wiliansilvazup Nov 16, 2020
74bd7ab
Adding some cryptography rules to csharp cli
nathanmartinszup Nov 16, 2020
40985bf
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
nathanmartinszup Nov 16, 2020
8bc16ac
Fixing total rules csharp
wiliansilvazup Nov 16, 2020
77f7b0f
Adding weak cipher rules
nathanmartinszup Nov 16, 2020
617338c
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
nathanmartinszup Nov 16, 2020
0f19eef
Adding more rules of csharp
wiliansilvazup Nov 16, 2020
29f9c53
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 16, 2020
87ba516
Fixing test
wiliansilvazup Nov 16, 2020
e320a50
Adding more csharp rules
nathanmartinszup Nov 16, 2020
6d7a87a
Updating branch and fixing conflicts
nathanmartinszup Nov 16, 2020
b9f54ac
add NewCsharpRegularDebugBuildEnabled
wiliansilvazup Nov 16, 2020
d00edae
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 16, 2020
8807d43
add NewCsharpRegularDebugBuildEnabled
wiliansilvazup Nov 16, 2020
520bc81
Adding custom errors disabled rule
nathanmartinszup Nov 16, 2020
f7fb8b1
Updating branch
nathanmartinszup Nov 16, 2020
9cac521
Adding rules csharp
wiliansilvazup Nov 16, 2020
3e19f8c
Adding rule vulnerable package reference
nathanmartinszup Nov 16, 2020
fa736a4
Adding rule jwt signature validation disabled
nathanmartinszup Nov 16, 2020
7400d6e
Add cors allow origin wildcard rules
nathanmartinszup Nov 16, 2020
655e7f7
Adding NewCsharpAndFormsAuthenticationCookielessMode
wiliansilvazup Nov 16, 2020
33add16
Adding regular anti forgery token rule
nathanmartinszup Nov 16, 2020
c92a1ea
Adding form validations
wiliansilvazup Nov 16, 2020
7721791
Adding missing authorize attribute rule
nathanmartinszup Nov 16, 2020
9c7fa78
Adding rules of xml in csharp
wiliansilvazup Nov 16, 2020
71f9d28
Merge
wiliansilvazup Nov 16, 2020
da74056
Fix test
wiliansilvazup Nov 16, 2020
80465e6
Adding more csharp rules
nathanmartinszup Nov 16, 2020
5412bb8
Adding password lockout disabled rule
nathanmartinszup Nov 16, 2020
e251718
Adding more rules in csharp of cookies and assinatures
wiliansilvazup Nov 16, 2020
efe03b8
Fix
wiliansilvazup Nov 16, 2020
da70c28
Adding cross site rules
wiliansilvazup Nov 17, 2020
70b00d3
Weak password rule
nathanmartinszup Nov 17, 2020
bc1c9b4
Adding ldap injection filter rule
nathanmartinszup Nov 17, 2020
8bef8fa
Adding more rules in csharp
wiliansilvazup Nov 17, 2020
bb305ce
Adding more rules in csharp
wiliansilvazup Nov 17, 2020
6c9afb8
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 17, 2020
4f1e975
Adding more rules in csharp
wiliansilvazup Nov 17, 2020
01b93e6
Adding ldap injection rules
nathanmartinszup Nov 17, 2020
2d40f12
Adding more rules in csharp
wiliansilvazup Nov 17, 2020
cdf0d7b
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 17, 2020
4f4d6b8
Adding csharp in deployments to up version
wiliansilvazup Nov 17, 2020
89e8121
Adding csharp in deployments to up version
wiliansilvazup Nov 17, 2020
40946c6
Rename test zip to csharp
wiliansilvazup Nov 17, 2020
0841fa4
Adding horusec csharp cli
nathanmartinszup Nov 17, 2020
14f2dc3
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
nathanmartinszup Nov 17, 2020
c32cb21
Change language to csharp
wiliansilvazup Nov 17, 2020
99afe00
Adding test to check netcore is deprecated
wiliansilvazup Nov 17, 2020
eb9d735
Updating regular rules
nathanmartinszup Nov 17, 2020
7e83906
Adding rule no log sensitive information in console
wiliansilvazup Nov 17, 2020
50164fe
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 17, 2020
22d00e2
Fix conflict
wiliansilvazup Nov 17, 2020
f966e27
Fixing error removing old regular expressions
nathanmartinszup Nov 17, 2020
bea32ce
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
nathanmartinszup Nov 17, 2020
e52c491
Update weak rsa key length
wiliansilvazup Nov 17, 2020
7576cef
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 17, 2020
df5e0d1
Removing deplicated rule
nathanmartinszup Nov 17, 2020
906a6c2
Fixing rules of java min 128 bits in key generator
wiliansilvazup Nov 17, 2020
d2b9402
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
nathanmartinszup Nov 17, 2020
3e83320
Adding unit tests in csharp engine
wiliansilvazup Nov 17, 2020
84e3961
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 17, 2020
8d73be2
Fixing fmt lint
wiliansilvazup Nov 17, 2020
3d84b27
Fixing test
wiliansilvazup Nov 17, 2020
df016d4
Fixing test
wiliansilvazup Nov 17, 2020
2182b4a
Adding readme.md in horusec-csharp
wiliansilvazup Nov 17, 2020
f9e68a1
Update README.md
wiliansilvazup Nov 17, 2020
289296c
Fixing tests
wiliansilvazup Nov 17, 2020
7c45e92
Merge branch 'feature/horusec-csharp' of github.com:ZupIT/horusec int…
wiliansilvazup Nov 17, 2020
5d784c6
Merge branch 'develop' of github.com:ZupIT/horusec into feature/horus…
wiliansilvazup Nov 18, 2020
ac31e95
Merge and update doc
wiliansilvazup Nov 18, 2020
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
46 changes: 46 additions & 0 deletions .github/workflows/csharp-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: HorusecCSharpPipeline

on:
push:
branches: [ "master", "develop" ]
pull_request:
branches: [ "**" ]

jobs:
install-build-test-fmt-lint:
name: install-build-test-fmt-lint
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.14
id: go
- name: Check out code
uses: actions/checkout@v2
- name: fmt
run: |
echo "==> Checking that code complies with gofmt requirements..."
gofmt_files=$(gofmt -l `find ./horusec-csharp -name '*.go' | grep -v vendor`)
echo $gofmt_files
if [ ! -z $gofmt_files ]; then
echo 'gofmt needs running on the following files:'
echo "$gofmt_files"
echo "You can use the command: \`gofmt -w \$(gofmt -l \'find ./horusec-csharp -name \'*.go\' | grep -v vendor)\` to reformat code."
exit 1
fi
echo "=) The project horusec-csharp it's OK!"
- name: lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.25.0
./bin/golangci-lint run -v --timeout=2m -c .golangci.yml ./horusec-csharp/...
- name: test
run: |
go clean -testcache
go test -v ./horusec-csharp/... -timeout=2m -parallel=1 -failfast -short
# - name: coverage
# run: make coverage-horusec-csharp
- name: build
run: go build -o "./tmp/bin/horusec-csharp" ./horusec-csharp/cmd/app/main.go

2 changes: 1 addition & 1 deletion .github/workflows/deploy-cli-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
tool_name:
description: 'Tool to deploy on dockerhub: bandit, brakeman, gitleaks, gosec, npmaudit, safety, securitycodescan, hcl, spotbugs, horusec-kotlin, horusec-java, horusec-leaks'
description: 'Tool to deploy on dockerhub: bandit, brakeman, gitleaks, gosec, npmaudit, safety, securitycodescan, hcl, spotbugs, horusec-kotlin, horusec-java, horusec-leaks, horusec-csharp'
required: true
update_type:
description: 'Update Type: alpha, rc, release, minor, major'
Expand Down
39 changes: 19 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,38 +153,37 @@ install-semver:
chmod +x ./deployments/scripts/install-semver.sh
./deployments/scripts/install-semver.sh

PATH_BINARY_BUILD_CLI ?= $(GOPATH)/bin
build-install-cli:
$(GO) build -o horusec ./horusec-cli/cmd/horusec/main.go
chmod +x horusec
rm -rf $(GOPATH)/bin/horusec
mv horusec $(GOPATH)/bin
cd ..
rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec" &> /dev/null
$(GO) build -o "$(PATH_BINARY_BUILD_CLI)/horusec" ./horusec-cli/cmd/horusec/main.go
chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec"
horusec version

build-install-leaks-cli:
$(GO) build -o horusec ./horusec-leaks/cmd/app/main.go
chmod +x horusec
rm -rf $(GOPATH)/bin/horusec-leaks
mv horusec $(GOPATH)/bin/horusec-leaks
cd ..
rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-leaks" &> /dev/null
$(GO) build -o "$(PATH_BINARY_BUILD_CLI)/horusec-leaks" ./horusec-leaks/cmd/app/main.go
chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-leaks"
horusec-leaks version

build-install-kotlin-cli:
$(GO) build -o horusec ./horusec-kotlin/cmd/app/main.go
chmod +x horusec
rm -rf $(GOPATH)/bin/horusec-kotlin
mv horusec $(GOPATH)/bin/horusec-kotlin
cd ..
rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-kotlin" &> /dev/null
$(GO) build -o "$(PATH_BINARY_BUILD_CLI)/horusec-kotlin" ./horusec-kotlin/cmd/app/main.go
chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-kotlin"
horusec-kotlin version

build-install-java-cli:
$(GO) build -o horusec ./horusec-java/cmd/app/main.go
chmod +x horusec
rm -rf $(GOPATH)/bin/horusec-java
mv horusec $(GOPATH)/bin/horusec-java
cd ..
rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-java" &> /dev/null
$(GO) build -o "$(PATH_BINARY_BUILD_CLI)/horusec-java" ./horusec-java/cmd/app/main.go
chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-java"
horusec-java version

build-install-csharp-cli:
rm -rf "$(PATH_BINARY_BUILD_CLI)/horusec-csharp" &> /dev/null
$(GO) build -o "$(PATH_BINARY_BUILD_CLI)/horusec-csharp" ./horusec-csharp/cmd/app/main.go
chmod +x "$(PATH_BINARY_BUILD_CLI)/horusec-csharp"
horusec-csharp version

# ========================================================================================= #

update-cli:
Expand Down
12 changes: 8 additions & 4 deletions deployments/scripts/update-image-tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ getDirectoryAndImageNameByToolName () {
IMAGE_NAME="horuszup/horusec-java"
DIRECTORY_CONFIG="$CURRENT_FOLDER/horusec-cli/internal/services/formatters/java/horusecjava/config.go"
DIRECTORY_SEMVER="$CURRENT_FOLDER/horusec-java";;
"horusec-csharp")
IMAGE_NAME="horuszup/horusec-csharp"
DIRECTORY_CONFIG="$CURRENT_FOLDER/horusec-cli/internal/services/formatters/csharp/horuseccsharp/config.go"
DIRECTORY_SEMVER="$CURRENT_FOLDER/horusec-csharp";;
"horusec-leaks")
IMAGE_NAME="horuszup/horusec-leaks"
DIRECTORY_CONFIG="$CURRENT_FOLDER/horusec-cli/internal/services/formatters/leaks/horusecleaks/config.go"
DIRECTORY_SEMVER="$CURRENT_FOLDER/horusec-leaks";;
*)
echo "Param Tool Name is invalid, please use the examples bellow allowed and try again!"
echo "Params Tool Name allowed: bandit, brakeman, gitleaks, gosec, npmaudit, safety, securitycodescan, hcl, spotbugs, horusec-kotlin, horusec-java, horusec-leaks"
echo "Params Tool Name allowed: bandit, brakeman, gitleaks, gosec, npmaudit, safety, securitycodescan, hcl, spotbugs, horusec-kotlin, horusec-java, horusec-leaks, horusec-csharp"
exit 1;;
esac
}
Expand Down Expand Up @@ -172,7 +176,7 @@ updateImage () {
updateVersionInConfigFile
updateVersionInCliVersionFile

if [[ "$TOOL_NAME" == "horusec-leaks" || "$TOOL_NAME" == "horusec-kotlin" || "$TOOL_NAME" == "horusec-java" ]]
if [[ "$TOOL_NAME" == "horusec-leaks" || "$TOOL_NAME" == "horusec-kotlin" || "$TOOL_NAME" == "horusec-java" || "$TOOL_NAME" == "horusec-csharp" ]]
then
DIRECTORY_SEMVER="$DIRECTORY_SEMVER/deployments"
fi
Expand All @@ -195,7 +199,7 @@ updateVersionInConfigFile () {
}

updateVersionInCliVersionFile () {
if [[ "$TOOL_NAME" == "horusec-leaks" || "$TOOL_NAME" == "horusec-kotlin" || "$TOOL_NAME" == "horusec-java" ]]
if [[ "$TOOL_NAME" == "horusec-leaks" || "$TOOL_NAME" == "horusec-kotlin" || "$TOOL_NAME" == "horusec-java" || "$TOOL_NAME" == "horusec-csharp" ]]
then
sed -i -e "s/{{VERSION_NOT_FOUND}}/$NEW_RELEASE/g" "./development-kit/pkg/cli_standard/cmd/version/version.go"
fi
Expand All @@ -207,7 +211,7 @@ rollbackVersionInConfigFile () {
}

rollbackVersionInCliVersionFile () {
if [[ "$TOOL_NAME" == "horusec-leaks" || "$TOOL_NAME" == "horusec-kotlin" || "$TOOL_NAME" == "horusec-java" ]]
if [[ "$TOOL_NAME" == "horusec-leaks" || "$TOOL_NAME" == "horusec-kotlin" || "$TOOL_NAME" == "horusec-java" || "$TOOL_NAME" == "horusec-csharp" ]]
then
sed -i -e "s/$NEW_RELEASE/{{VERSION_NOT_FOUND}}/g" "./development-kit/pkg/cli_standard/cmd/version/version.go"
fi
Expand Down
65 changes: 65 additions & 0 deletions development-kit/pkg/engines/csharp/analysis/analysis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package analysis

import (
"encoding/json"

engine "github.com/ZupIT/horusec-engine"
"github.com/ZupIT/horusec-engine/text"
"github.com/ZupIT/horusec/development-kit/pkg/cli_standard/config"
"github.com/ZupIT/horusec/development-kit/pkg/engines/csharp/rules"
"github.com/ZupIT/horusec/development-kit/pkg/utils/logger"
)

type Interface interface {
StartAnalysis() error
}

type Analysis struct {
configs *config.Config
serviceRules rules.Interface
}

func NewAnalysis(configs *config.Config) Interface {
return &Analysis{
configs: configs,
serviceRules: rules.NewRules(),
}
}

func (a *Analysis) StartAnalysis() error {
textUnit, err := text.LoadDirIntoSingleUnit(a.configs.GetProjectPath(), []string{
".cs", ".vb", ".cshtml", ".csproj", ".xml"})
if err != nil {
return err
}
a.logJSON("Text Unit selected is: ", textUnit)

allRules := a.serviceRules.GetAllRules()
a.logJSON("All rules selected are: ", allRules)

outputFilePath := a.configs.GetOutputFilePath()
logger.LogDebugWithLevel("Sending units and rules to engine "+
" and expected response in path: ", logger.DebugLevel, outputFilePath)
return engine.RunOutputInJSON([]engine.Unit{textUnit}, allRules, outputFilePath)
}

func (a *Analysis) logJSON(message string, content interface{}) {
b, err := json.Marshal(content)
if err == nil {
logger.LogTraceWithLevel(message, logger.DebugLevel, string(b))
}
}
57 changes: 57 additions & 0 deletions development-kit/pkg/engines/csharp/analysis/analysis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package analysis

import (
"encoding/json"
engine "github.com/ZupIT/horusec-engine"
"github.com/ZupIT/horusec/development-kit/pkg/cli_standard/config"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)

func TestNewAnalysis(t *testing.T) {
assert.IsType(t, NewAnalysis(config.NewConfig()), &Analysis{})
}

func TestAnalysis_StartAnalysis(t *testing.T) {
t.Run("Should return success when read analysis and return seven vulnerabilities", func(t *testing.T) {
configs := config.NewConfig()
configs.SetOutputFilePath("./csharp-tmp.output.json")
configs.SetProjectPath("../../examples/csharp-generic-vuln")
err := NewAnalysis(configs).StartAnalysis()
assert.NoError(t, err)
fileBytes, err := ioutil.ReadFile("./csharp-tmp.output.json")
data := []engine.Finding{}
_ = json.Unmarshal(fileBytes, &data)
assert.NoError(t, os.RemoveAll(configs.GetOutputFilePath()))
assert.Equal(t, 6, len(data))
})
t.Run("Should return error when create file", func(t *testing.T) {
configs := config.NewConfig()
configs.SetOutputFilePath("./////")
err := NewAnalysis(configs).StartAnalysis()
assert.Error(t, err)
})
t.Run("Should return error when get units in project path", func(t *testing.T) {
configs := config.NewConfig()
configs.SetOutputFilePath("./////")
configs.SetProjectPath("./not exists path")
err := NewAnalysis(configs).StartAnalysis()
assert.Error(t, err)
})
}
43 changes: 43 additions & 0 deletions development-kit/pkg/engines/csharp/rules/rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package rules

import (
engine "github.com/ZupIT/horusec-engine"
"github.com/ZupIT/horusec/development-kit/pkg/enums/engine/advisories/csharp"
)

type Interface interface {
GetAllRules() (rules []engine.Rule)
}

type Rules struct{}

func NewRules() Interface {
return &Rules{}
}

func (r *Rules) GetAllRules() (rules []engine.Rule) {
for index := range csharp.AllRulesCsharpAnd() {
rules = append(rules, csharp.AllRulesCsharpAnd()[index])
}
for index := range csharp.AllRulesCsharpOr() {
rules = append(rules, csharp.AllRulesCsharpOr()[index])
}
for index := range csharp.AllRulesCsharpRegular() {
rules = append(rules, csharp.AllRulesCsharpRegular()[index])
}
return rules
}
39 changes: 39 additions & 0 deletions development-kit/pkg/engines/csharp/rules/rules_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package rules

import (
"testing"

"github.com/ZupIT/horusec-engine/text"
"github.com/stretchr/testify/assert"
)

func TestNewRules(t *testing.T) {
assert.IsType(t, NewRules(), &Rules{})
}

func TestRules_GetAllRules(t *testing.T) {
t.Run("Should return all rules enable", func(t *testing.T) {
rules := NewRules().GetAllRules()
totalRegexes := 0
for i := range rules {
textRule := rules[i].(text.TextRule)
totalRegexes += len(textRule.Expressions)
}
assert.Greater(t, len(rules), 0)
assert.Greater(t, totalRegexes, 0)
})
}
15 changes: 15 additions & 0 deletions development-kit/pkg/engines/examples/csharp-generic-vuln/Errors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NetCoreVulnerabilities
{
public class Errors
{
public void NotUsedVar()
{
var neverUsedVar1 = "";
}

public void NotUsedVar2()
{
var neverUsedVar2 = "";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="SecurityCodeScan.VS2017" Version="3.5.0" />
</ItemGroup>

</Project>
Loading