Skip to content

Instantly share code, notes, and snippets.

View InfoSec812's full-sized avatar

Deven Phillips InfoSec812

View GitHub Profile
@InfoSec812
InfoSec812 / Jenkinsfile-1.groovy
Last active March 21, 2019 17:22
Scaffolding A podTemplate For Jenkins
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '50'))
timeout(time: 20, unit: 'MINUTES') // If the build takes longer than 20 minutes, fail automatically
}
agent {
kubernetes {
label "zaproxy-maven-sidecars-${env.BUILD_ID}"
defaultContainer 'jenkins-slave-mvn'
yaml """
@InfoSec812
InfoSec812 / Jenkinsfile.groovy
Last active March 6, 2019 13:14
Load podTemplate from K8s ConfigMap
// Pull the configmap from the K8 API using the Jenkins service account and store it in the podTemplateYaml variable
def podTemplateYaml = ''
openshift.withCluster() {
openshift.withProject() {
cmsel = opeshift.selector("configmap", [role: 'jenkins-slave' ])
cmsel.watch {
podTemplateYaml = it.object().data[bw-maven]
}
}
}
@InfoSec812
InfoSec812 / Jenkinsfile
Created January 21, 2019 15:48
Example Jenkinsfile showing how to use Zed Attack Proxy in conjunction with Selenium
import groovy.json.JsonSlurper
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '50'))
timeout(time: 20, unit: 'MINUTES') // If the build takes longer than 20 minutes, fail automatically
}
agent {
kubernetes {
label "zaproxy-maven-sidecars-${env.BUILD_ID}"
@InfoSec812
InfoSec812 / jest_assertions_vue.test.js
Created November 3, 2018 10:55
Example Jest Assertions For Vue 3 Applications
// Mount a Vue component into the Virtual DOM, and pass any mocked objects which are appropriate
wrapper = mount(MyComponent, {
localVue,
mocks: { // Implement the mocks here!
$axios,
$router
}
});
// Make an assertion against the component's '$data' object
@InfoSec812
InfoSec812 / jest_mock_assertions.test.js
Created November 3, 2018 10:43
Jest Assertions On Mocked Methods
expect(axios.put).toHaveBeenCalledTimes(1);
// Check to see if the parameters are correct
expect(axios.put).toHaveBeenCalledWith('/api/v1/user', { username: USERNAME, password: PASSWORD });
// Check to ensure that the method reached a "return" statement
expect(axios.put).toHaveReturned();
@InfoSec812
InfoSec812 / axios_mock.test.js
Created November 3, 2018 10:36
Mocked Axios Method Using Jest
axios.get = jest.fn((path, options) => {
expect(path).toEqual('/api/v1/user');
expect(options.username).toEqual(USERNAME);
expect(options.password).toEqual(PASSWORD);
let response = {
// 'data' is the response that was provided by the server
data: TOKEN,
// 'status' is the HTTP status code from the server response
status: 200,
// 'statusText' is the HTTP status message from the server response
@InfoSec812
InfoSec812 / test.spec.js
Last active November 2, 2018 19:38
Async Vue Test Utils Example
import { shallowMount } from '@vue/test-utils'
import MessageToggle from '@/components/MessageToggle.vue'
import Message from '@/components/Message'
// Define the test method to be prefixed with `async`
describe('MessageToggle.vue', async () => {
it('toggles msg passed to Message when button is clicked', () => {
const wrapper = shallowMount(MessageToggle)
const button = wrapper.find('#toggle-message')
button.trigger('click')
@InfoSec812
InfoSec812 / test.spec.js
Created November 2, 2018 19:24
Another Vue Test Utils Example
import { shallowMount } from '@vue/test-utils'
import MessageToggle from '@/components/MessageToggle.vue'
import Message from '@/components/Message'
describe('MessageToggle.vue', () => {
it('toggles msg passed to Message when button is clicked', () => {
const wrapper = shallowMount(MessageToggle)
const button = wrapper.find('#toggle-message')
button.trigger('click')
const MessageComponent = wrapper.find(Message)
@InfoSec812
InfoSec812 / test.spec.js
Created November 2, 2018 19:21
Vue Test Utils Example
import {
shallowMount
} from '@vue/test-utils'
import List from '@/components/List.vue'
import {
createRenderer
} from 'vue-server-renderer'
describe('List.vue', () => {
it('renders li for each item in props.items', () => {
@InfoSec812
InfoSec812 / example.js
Created November 2, 2018 18:53
Demonstrating the use of CSS Selectors in JavaScript
var clickCount = 0;
function buttonClickHandler() {
clickCount++;
document.querySelector("button[type]").innerHTML = "Clicked " + clickCount + " times";
}