aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/dev-branch.yml87
-rw-r--r--.github/workflows/feature-branch.yml21
-rw-r--r--.github/workflows/main-branch.yml17
-rw-r--r--Dockerfile.dev10
-rw-r--r--Makefile8
-rw-r--r--src/browser-cli.h2
-rw-r--r--src/server-cli.c4
-rw-r--r--src/server-cli.h2
-rw-r--r--src/server-connection.c4
-rw-r--r--src/server-connection.h2
-rw-r--r--src/server.c8
-rw-r--r--tests/browser-net.tests.c20
12 files changed, 145 insertions, 40 deletions
diff --git a/.github/workflows/dev-branch.yml b/.github/workflows/dev-branch.yml
new file mode 100644
index 0000000..6d66da2
--- /dev/null
+++ b/.github/workflows/dev-branch.yml
@@ -0,0 +1,87 @@
+name: Tests, analysis and push to dev dockerhub
+on:
+ push:
+ branches:
+ - dev
+jobs:
+ # This is done to prevent potential race conditions;
+ # multiple jobs start with the source code, but since
+ # they have no "needs", one could start a little bit later,
+ # and in meantime a commit could be pushed
+ Clone-repo:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ submodules: recursive
+ - uses: actions/upload-artifact@v3
+ with:
+ name: source-code
+ path: .
+
+ Tests:
+ runs-on: ubuntu-latest
+ needs: Clone-repo
+ steps:
+ - uses: actions/download-artifact@v3
+ with:
+ name: source-code
+ path: .
+ - name: Run tests
+ run: make tests
+
+ Static-analysis:
+ runs-on: ubuntu-latest
+ needs: Clone-repo
+ steps:
+ - uses: actions/download-artifact@v3
+ with:
+ name: source-code
+ path: .
+ - name: Run satic analysis
+ run: make static-analysis
+
+ Security-analysis:
+ runs-on: ubuntu-latest
+ needs: Clone-repo
+ steps:
+ - uses: actions/download-artifact@v3
+ with:
+ name: source-code
+ path: .
+ - name: Run security analysis
+ run: make security-analysis
+
+ Build:
+ runs-on: ubuntu-latest
+ needs: [ Tests, Static-analysis, Security-analysis ]
+ steps:
+ - uses: actions/download-artifact@v3
+ with:
+ name: source-code
+ path: .
+ - name: Build server and browser
+ run: make dev
+ - uses: actions/upload-artifact@v3
+ with:
+ name: dev-build-files
+ path: ./build
+
+ Build-docker-and-push:
+ name: Build the docker container image and push it to dockerhub
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/download-artifact@v3
+ with:
+ name: dev-build-files
+ path: ./build
+ - uses: actions/checkout@v4
+ - uses: docker/login-action@v3
+ with:
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
+ - uses: docker/build-push-action@v5
+ with:
+ push: true
+ file: Dockerfile.dev
+ tags: ${{ secrets.DOCKERHUB_USERNAME }}/pico-web-dev:latest
diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml
index 54c0c6b..3ff1833 100644
--- a/.github/workflows/feature-branch.yml
+++ b/.github/workflows/feature-branch.yml
@@ -1,4 +1,4 @@
-name: feature-branch
+name: Tests and static analysis
on:
push:
branches-ignore:
@@ -13,6 +13,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
+ with:
+ submodules: recursive
- uses: actions/upload-artifact@v3
with:
name: source-code
@@ -22,15 +24,20 @@ jobs:
runs-on: ubuntu-latest
needs: Clone-repo
steps:
- - uses: actions/checkout@v4
- - name: Build server and browser
+ - uses: actions/download-artifact@v3
+ with:
+ name: source-code
+ path: .
+ - name: Run tests
run: make tests
- Static analysis:
+ Static-analysis:
runs-on: ubuntu-latest
needs: Clone-repo
steps:
- - uses: actions/checkout@v4
- - name: Build server and browser
+ - uses: actions/download-artifact@v3
+ with:
+ name: source-code
+ path: .
+ - name: Run static analysis
run: make static-analysis
-
diff --git a/.github/workflows/main-branch.yml b/.github/workflows/main-branch.yml
index d8584cb..8534344 100644
--- a/.github/workflows/main-branch.yml
+++ b/.github/workflows/main-branch.yml
@@ -1,14 +1,16 @@
-name: Push image to dockerhub
+name: Create release and push production server image to dockerhub
on:
push:
branches:
- main
jobs:
- build-and-push:
+ Build-docker-and-push:
name: Build the docker container image and push it to dockerhub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
+ with:
+ submodules: recursive
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
@@ -18,3 +20,14 @@ jobs:
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/pico-web-server:latest
+ Release:
+ name: Make github release
+ runs-on: ubuntu-latest
+ needs: Build-docker-and-push
+ steps:
+ - uses: actions/checkout@v4
+ - uses: rymndhng/release-on-push-action@master
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ bump_version_scheme: minor
diff --git a/Dockerfile.dev b/Dockerfile.dev
new file mode 100644
index 0000000..328f4a6
--- /dev/null
+++ b/Dockerfile.dev
@@ -0,0 +1,10 @@
+FROM alpine:latest
+
+RUN apk update && apk upgrade
+RUN apk add bash musl-dev gcc make gdb
+
+COPY ./build /usr/build
+
+EXPOSE 8080
+WORKDIR /usr/build
+CMD /bin/bash
diff --git a/Makefile b/Makefile
index 692aba2..73b063a 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,10 @@
CC_SANA ?= clang
CFLAGS_SANA ?= --analyze -Xclang -analyzer-output=text
+# Security analysis
+CC_CANA ?= flawfinder
+CFLAGS_CANA ?= --error-level=3
+
.PHONY: all
all: build
@@ -21,6 +25,10 @@ tests:
static-analysis:
$(CC_SANA) $(CFLAGS_SANA) ./src/*
+.PHONY: security-analysis
+security-analysis:
+ $(CC_CANA) $(CFLAGS_CANA) ./src
+
.PHONY: clean
clean:
cd ./src/ && $(MAKE) clean
diff --git a/src/browser-cli.h b/src/browser-cli.h
index a164dc9..8709231 100644
--- a/src/browser-cli.h
+++ b/src/browser-cli.h
@@ -1,7 +1,7 @@
#ifndef BROWSER_CLI
#define BROWSER_CLI
-#include <sds/sds.h>
+#include "sds/sds.h"
void initRendering();
void freeRendering();
diff --git a/src/server-cli.c b/src/server-cli.c
index 707c3ef..5e84ff6 100644
--- a/src/server-cli.c
+++ b/src/server-cli.c
@@ -1,5 +1,5 @@
-#include <util.h>
-#include <server-connection.h>
+#include "util.h"
+#include "server-connection.h"
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
diff --git a/src/server-cli.h b/src/server-cli.h
index b5b5875..8bc6ff2 100644
--- a/src/server-cli.h
+++ b/src/server-cli.h
@@ -1,7 +1,7 @@
#ifndef H_SERVER_CLI
#define H_SERVER_CLI
-#include <sds/sds.h>
+#include "sds/sds.h"
void handleCLI(sds **vhosts, int vhostsc);
diff --git a/src/server-connection.c b/src/server-connection.c
index 466b259..3edd120 100644
--- a/src/server-connection.c
+++ b/src/server-connection.c
@@ -1,4 +1,4 @@
-#include <server-connection.h>
+#include "server-connection.h"
#include <stdio.h>
#include <unistd.h>
@@ -6,7 +6,7 @@
#include <sys/stat.h>
#include <string.h>
-#include <util.h>
+#include "util.h"
sds constructFilePath(const sds root, const char* file);
void sanitizeAddress(char* address);
diff --git a/src/server-connection.h b/src/server-connection.h
index 71447ff..689fbf4 100644
--- a/src/server-connection.h
+++ b/src/server-connection.h
@@ -1,7 +1,7 @@
#ifndef H_SERVER_CONNECTION
#define H_SERVER_CONNECTION
-#include <sds/sds.h>
+#include "sds/sds.h"
#define vh_user 0
#define vh_path 1
diff --git a/src/server.c b/src/server.c
index aeff800..1c157fe 100644
--- a/src/server.c
+++ b/src/server.c
@@ -14,11 +14,11 @@
#include <sys/select.h>
#include <string.h>
-#include <sds/sds.h>
-#include <util.h>
+#include "sds/sds.h"
+#include "util.h"
-#include <server-connection.h>
-#include <server-cli.h>
+#include "server-connection.h"
+#include "server-cli.h"
int createCommunicationSocket(const char* ip, const char* port) {
int fd_socket = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
diff --git a/tests/browser-net.tests.c b/tests/browser-net.tests.c
index 05a4a7c..0e0ee7b 100644
--- a/tests/browser-net.tests.c
+++ b/tests/browser-net.tests.c
@@ -21,23 +21,3 @@ void test_get_page_ReturnsEmptyLine_WhenURLIsBlank(void) {
sdsfree(page);
}
-
-void test_get_page_ReturnsMessage_WhenCannotConnectToServer(void) {
- streq_ExpectAndReturn(URL, "blank", 0);
- herrc_Expect(3, "socket");
- atop_ExpectAndReturn("0", 0);
- /* aton_ExpectAndReturn("255.255.255.255", NULL, -1); */
- /* aton_IgnoreArg_output(); */
- herrc_Expect(0, "inet_aton");
- herrc_Expect(0, "connect");
-
- sds page = get_page("255.255.255.255", "0", URL);
-
- TEST_ASSERT_EQUAL_STRING(page, "Couldn't connect to server!\n");
-
- sdsfree(page);
-}
-
-void test_get_page_ReturnsGivenPage_WhenURLIsCorrect(void) {
- TEST_ASSERT_TRUE(1);
-}