Skip to content

Commit

Permalink
Use bind_params to avoid SQL injection
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Mar 22, 2024
1 parent 93959b3 commit ab9cba7
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 155 deletions.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

# Maintain dependencies for client
- package-ecosystem: "npm"
directory: "/client"
schedule:
interval: "daily"
open-pull-requests-limit: 10

# Maintain dependencies for server
- package-ecosystem: "pip"
directory: "/server"
schedule:
interval: "daily"
open-pull-requests-limit: 10
46 changes: 46 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '41 3 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
137 changes: 137 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---

name: CI

on:
# Triggers the workflow on push or pull request events
push:
pull_request:
release:
tags:
- 'v*'
types: [published]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
Server_tests:
name: Server tests

runs-on: ubuntu-latest

# Test different python versions
strategy:
fail-fast: false
matrix:
python-version: ['3.9']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check out repo
uses: actions/checkout@v2
- name: Setup InfluxDB
uses: influxdata/influxdb-action@v3
with:
influxdb_version: 1.11.5
influxdb_org: influxdata
influxdb_user: ""
influxdb_password: ""
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'requirements/*.txt'

- name: Display Python version
run: |
python -c "import sys; print(sys.version)"
echo coverage: .${{ matrix.coverage }}.
- name: Install dependencies
run: |
python -m pip install pip setuptools wheel
pip install --upgrade pip
pip install -r ./requirements/test.txt
pip install flake8
- name: Run flake8
run: |
cd ./server
flake8 .
- name: Run tests with coverage
run: |
cd ./server
coverage run -m pytest test --cov-report xml --cov=server
timeout-minutes: 20

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
if: success()


Client_build:
name: Client build

runs-on: ubuntu-latest

steps:
- name: Run errands
run: |
sudo apt -y install curl
- name: Checkout
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "DIR=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.DIR }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: "20.11.1"
cache: "yarn"
cache-dependency-path: '**/yarn.lock'

- name: Install dependencies
shell: bash
run: |
source ~/.nvm/nvm.sh
rm -rf ~/.yarn
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.22.19
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
yarn -v
# nvm install "16.10.0"
# nvm use "16.10.0"
env:
VNM_DIR: ~/.nvm

- name: Run tests
shell: bash
run: |
cd client
yarn install
CI=true yarn test
yarn build
env:
CI: true
VNM_DIR: ~/.nvm
INLINE_RUNTIME_CHUNK: False
IMAGE_INLINE_SIZE_LIMIT: 0
timeout-minutes: 15
3 changes: 0 additions & 3 deletions client/src/__tests__/base.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import I18n from "../locale/I18n";
import en from "../locale/en";
import nl from "../locale/nl";
import Adapter from "enzyme-adapter-react-16";
import Enzyme from "enzyme"

const start = () => {
//we need to use them, otherwise the imports are deleted when organizing them
Expand All @@ -11,7 +9,6 @@ const start = () => {
expect(nl).toBeDefined();
I18n.locale = "en";

Enzyme.configure({ adapter: new Adapter() })
};

test("Test suite must contain at least one test", () => {});
Expand Down
10 changes: 5 additions & 5 deletions client/src/__tests__/utils/QueryParameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import {replaceQueryParameter, getParameterByName} from "../../utils/QueryParame

test("Replace query parameters", () => {
const replaced = replaceQueryParameter("?test=bogus", "test", "value");
expect(replaced).toBe("?test=value");
expect(replaced).toBe("test=value");
});

test("Replace query parameters preserve existing", () => {
const replaced = replaceQueryParameter("?test=bogus&name=x", "test", "value");
expect(replaced).toBe("?name=x&test=value");
expect(replaced).toBe("test=value&name=x");
});

test("Replace query parameters", () => {
const replaced = replaceQueryParameter("", "test", "value");
expect(replaced).toBe("?test=value");
expect(replaced).toBe("test=value");
});

test("Parameter by name", () => {
expect("value", getParameterByName("name", "?name=value"))
expect(getParameterByName("name", "?name=value")).toBe("value");
});

test("Parameter by name not exists", () => {
expect("value", getParameterByName("", undefined))
expect(getParameterByName("nope", "?name=value")).toBe(null);
});
14 changes: 5 additions & 9 deletions client/src/components/CheckBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@ import Tooltip from "./Tooltip";

export default function CheckBox({name, value, info, onChange, toolTip = null, readOnly = false}) {

const innerOnChange = e => {
e.cancelBubble = true;
e.stopPropagation();
onChange && onChange(e);
return false;
}

return (
<div className="checkbox">
<input type="checkbox"
id={name}
name={name}
checked={value}
onChange={innerOnChange}
onChange={onChange}
disabled={readOnly}/>
<label htmlFor={name}>
<button disabled={readOnly} onClick={innerOnChange}><CheckIcon/></button>
<button disabled={readOnly} onClick={e => onChange({target: {checked: !value}})}>
<CheckIcon/>
</button>

</label>
{info && <span>
<label htmlFor={name} className={`info ${readOnly ? "disabled" : ""}`}
Expand Down
1 change: 1 addition & 0 deletions client/src/components/GroupBy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {CSVDownload} from "react-csv";
import CheckBox from "./CheckBox";

export default class GroupBy extends React.PureComponent {

constructor() {
super();
this.state = {
Expand Down
6 changes: 0 additions & 6 deletions client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import "regenerator-runtime/runtime";
import {polyfill} from "es6-promise";
import React from 'react';

// import 'highcharts/css/highcharts.css';
//Do not change the order of highcharts imports
// import '@surfnet/sds/styles/sds.css';
//Do not change the order of @surfnet.sds style imports
// import '@surfnet/sds/cjs/index.css';

polyfill();

(() => {
Expand Down
19 changes: 11 additions & 8 deletions client/src/pages/Live.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {addDayDuplicates, addDays, daysBetween, getPeriod, unixFromDate, unixFro
import Filters from "../components/Filters";
import SelectPeriod from "../components/SelectPeriod";
import {DateTime} from "luxon";
import mockData from "../utils/data.json"

const minDiffByScale = {minute: 1, hour: 7, day: 90, week: 365, month: 365, quarter: 365, year: 365 * 5};
const maxDayDiffMainMeasurements = 14;
Expand Down Expand Up @@ -278,7 +277,7 @@ export default class Live extends React.Component {
}, this.componentDidMount);
} else {
const from = DateTime.fromJSDate(to).minus({"day": minDiffByScale[scale]}).startOf(scale).toJSDate();
this.setState({
this.setState({
data: [],
scale: scale,
from: from
Expand All @@ -293,13 +292,14 @@ export default class Live extends React.Component {

onChangeGroupBySp = e => {
let additionalState = {};
if (!this.state.groupedByIdp && e.target.checked) {
const checked = e.target.checked;
if (!this.state.groupedByIdp && checked) {
additionalState = this.initialStateGroupBy();
} else if (!e.target.checked) {
} else if (!checked) {
additionalState = this.initialStateNoGroupBy();
}
this.setState({
data: [], groupedBySp: e.target.checked,
data: [], groupedBySp: checked,
groupedByIdp: false,
institutionType: "",
...additionalState
Expand All @@ -308,13 +308,16 @@ export default class Live extends React.Component {

onChangeGroupByIdp = e => {
let additionalState = {};
if (!this.state.groupedBySp && e.target.checked) {
const checked = e.target.checked;
debugger;
if (!this.state.groupedBySp && checked) {
additionalState = this.initialStateGroupBy();
} else if (!e.target.checked) {
} else if (!checked) {
additionalState = this.initialStateNoGroupBy();
}
this.setState({
data: [], groupedByIdp: e.target.checked,
data: [],
groupedByIdp: checked,
groupedBySp: false,
institutionType: "",
...additionalState
Expand Down
15 changes: 0 additions & 15 deletions client/src/stylesheets/highchart_overrides.scss

This file was deleted.

Loading

0 comments on commit ab9cba7

Please sign in to comment.