Knowledge Bank
  • 🔭About Us
    • 👋Welcome to Securescape!
  • 👶Fundamentals
    • 🖥️Operating Systems (WIP)
      • Introduction to Operating Systems
      • Processes and Process Management
        • 📠Processes
        • 🧵Threads
        • 📅Scheduling
      • Memory Management
        • Virtual Memory Management
      • Storage Management
      • I/O Management
    • 🐧Linux (WIP)
      • Introduction to Linux
      • Linux System Management
    • ⚡Programming (WIP)
      • 🔗Assembly
      • 💪C(++/#)
      • 🐍Python
      • 👑Nim
      • 🔨Bash
        • Introduction to Bash Scripting
        • Variables, Loops, and Port Scanner
    • 🚩Networking (WIP)
      • 📶Networking 101
        • 🕸️Networking Basics
        • 🛑Protocols
        • 🧓IPv4
        • 🧒IPv6
      • 🪡Packet Tracer
        • Interface
        • Connections
        • Creating Networks
        • Virtual LANS & Trunks
      • 🕸️Subnetting
      • 🕵️Network Security
    • ✍️Report Writing (WIP)
      • 🔍Research Skills
      • 🏗️Structuring a Report
      • 🗃️Creating Templates
  • 🦂General Security
    • 🗒️Methodologies
      • 🇭🇰OSSTMM
      • 🐝OWASP
        • Web Security Testing Guide
        • Mobile Security Testing Guide
      • 🦅NIST
      • 🥢PTES
      • ⛓️Cyber Killchain
    • 🍔Binary Exploitation
      • ir0nstone's Binary Exploitation Notes
    • 🎩Cheat Sheets
      • Enumeration
        • Network Scan
        • Vulnerability Scan
        • Web Scan
      • Exploitation
        • Page 1
        • Payloads & Shells
      • Post Exploitation
        • Lay of The Land
        • Persistence
        • Data Exfiltration
        • Pivoting
      • Command & Control
      • Disassembly
        • ☢️Radare2
        • 🥜GDB
      • CEH Cheatsheet
  • ⚔️Offensive Security
    • 💡Hardware Exploitation
      • Intro to Hardware
    • 🥷Red Team
      • 🦠Malware Development
        • Crow Malware Development
        • 🪡C# Malware
      • 🏭Offensive Development
        • 🔧Offensive DevOps
          • 🏷️GitLab
            • GitLab Setup
            • Simple Calculator Project
            • Making our CI/CD Pipeline
            • Build Artifacts
          • 🌆TeamCity
            • TeamCity Setup
            • Creating TeamCity Projects
            • Obfuscating Payloads
          • 🍷Jenkins (WIP)
            • Jenkins Setup
            • Creating Pipelines
            • Managing Projects
            • API Interaction
        • 🏗️Infrastructure Development (WIP)
          • 🎮Command & Control Infrastructure
            • 🤖Command & Control Anatomy
              • Command & Control Frameworks
              • Ⓜ️Metasploit Framework
                • Installing Metasploit
                • Metasploit Basics
                • Advanced Features
                • Metasploit Documentation
              • 🐲Mythic Framework
                • Installing Mythic
                • Malleable Command & Control
                • All About Agents
                • Services
                • Mythic Documentation
            • 🚥Traffic Redirection
              • Nginx
              • Amazon Web Services
              • Microsoft Azure
              • Google Cloud Platform
              • Cloudflare Workers
            • 🥷Covert Infrastructure
              • Ensuring Resiliency
              • Traffic Masking
              • Network Rules
          • 🎣Phishing Infrastructure
            • 📧Email Anatomy
            • 🐟Phishing Infrastructure Setup
            • 🚚Payload Delivery
            • 🚩Removing Red Flags
          • 🪄Infrastructure as Code
            • 🏝️Terraform
              • Interacting with Docker
              • Going to the Cloud
              • Hybrid Deployment
            • 🧊Pulumi
            • 🎼Ansible
          • ⚙️Infrastructure Automation
            • 🦴Structuring our Project
            • 🏭Automating Server Setups
            • 🎼Orchestrating our Infrastructure
            • 🔧CI/CD Integration
      • 🏙️Active Directory (WIP)
        • Active Directory Overview
        • Authentication
        • AD Lab
      • Red Team Operations - Joas Santos
  • 🛡️Defensive Security
  • 📻Software Defined Radios
    • ⚠️Disclaimer
    • 📡Baofeng
      • Programming
  • 🧑‍🔬Home Lab
    • 💨Virtualisation
      • 🔸Proxmox
  • 🏁Capture The Flag
    • 🧊HackTheBox
      • 👾Cyber Apocalypse
        • Cyber Apocalypse 2023
    • 🐤TryHackMe
      • 🎄Advent of Code
      • 🚪Rooms
        • 🐥Basic Pentesting
        • 👨‍💻Blog
      • 👟Paths
    • 🏳️Competitions
      • Nahamcon
        • Nahamcon 2023
          • Binary Exploitation
            • Open Sesame
      • 👁️Iris CTF
  • 🦺DRAFTS
    • GS
      • 📱Mobile Application Security
      • 👨‍🔬Reverse Engineering
      • 🌐Web Application Security
      • 📌Information Security
      • 🔒Cryptography
      • 🤫Operational Security
    • DS
      • 🧠Threat Intelligence
        • 🦌ELK Stack
          • 🤸Elasticsearch
          • 🏕️Kibana
          • 🦤SELKS
        • 🚓Yara
      • 🏹Threat Hunting
      • 🧬Malware Analysis
        • Fundamentals
      • 🔬Forensics
        • 📶Network Forensics
          • 🦈Wireshark
          • 🥟TCP Dump
        • 💾Memory Forensics
          • ⚡Volatility
        • 💽Disk Forensics
          • 🐕Autopsy
        • 🪟Windows Forensics
        • 🐧Linux Forensics
      • 🌲Security Operations
        • Intrusion Detection & Prevention
          • 🐛Splunk
            • Splunk Basics
            • Integrating Suricata with Splunk
          • 🐗Suricata
            • Intro to Suricata
          • 🐽Snort
            • Snort Basics
        • Security Information and Event Management (SIEM)
        • Security Orchestration, Automation and Response (SOAR)
    • HL
      • 🖥️Hardware
    • OS
      • 📶Network Exploitation
      • 🌩️Cloud Exploitation
Powered by GitBook
On this page
  • Module Objectives
  • Creating a Project Repository
  • Making a simple calculator
  • Writing Test Cases

Was this helpful?

Edit on GitHub
  1. Offensive Security
  2. Red Team
  3. Offensive Development
  4. Offensive DevOps
  5. GitLab

Simple Calculator Project

PreviousGitLab SetupNextMaking our CI/CD Pipeline

Last updated 1 year ago

Was this helpful?

Module Objectives

  • Creating a simple project

  • Adding code

  • Uploading our code to GitLab

  • Writing test cases to check for failed and successful builds

Creating a Project Repository

Now that we have everything set up, we can start making projects. Start by logging into your normal user (if you haven't already), then go to Projects -> New Project. You can remove the README.

Once it's been created, git clone your project into a directory

Making a simple calculator

To test if our runner works, we will create a simple program which we can upload then run tests and configure pipelines for.

Let's make a simple calculator. I'll be using Go for this example

calculator.go
package main
import "fmt"


func Add(x, y int) (res int) {
	return x + y
}


func Subtract(x, y int) (res int) {
	return x - y
}


func main() {
	fmt.Println("Addition: ", Add(1, 2))
	fmt.Println("Subtraction: ", Subtract(4, 2))
}

Test this by running go run calculator.go

Addition:  3
Subtraction:  2

Now that it works, we can push our demo app to our repository

> git switch -c main
> git add .
> git commit -m "Calculator Demo"
> git push origin main

Writing Test Cases

Now that we have a functioning program, we can write a test case to check whether the values are acceptable, if not it will fail the build. We will reuse the code above for this

calculator.go
package main
import "fmt"


func Add(x, y int) (res int) {
	return x + y
}


func Subtract(x, y int) (res int) {
	return x - y
}


func main() {
	fmt.Println("Addition: ", Add(1, 2))
	fmt.Println("Subtraction: ", Subtract(4, 2))
}
calculator_test.go
package main
import "testing"

func TestAdd(t *testing.T){
	got := Add(4, 4)
	want:= 8

	if got != want {
		t.Errorf("got %q. wanted %q", got, want)
	}
}


func TestSubtract(t *testing.T){
	got := Subtract(6, 4)
	want:= 2

	if got != want {
		t.Errorf("got %q. wanted %q", got, want)
	}
}

To run the test:

> go mod init calculator
> go test

# Result
> go test         
PASS
ok      calculator      0.127s

We can test for failure as well by changing the want variable to a random integer/string

> go test
--- FAIL: TestAdd (0.00s)
    calculator_test.go:9: got '\b'. wanted '\x05'
--- FAIL: TestSubtract (0.00s)
    calculator_test.go:19: got '\x02'. wanted '\x03'
FAIL
exit status 1
FAIL    calculator      0.215s

Change back the values and push the code to your repository

⚔️
🥷
🏭
🔧
🏷️
Reference
Set your project to public or private - we can use private for this one since we have our SSH key uploaded
Cloning the project to our Windows host
Post-Push Repository