Skip to content

Commit

Permalink
Reorganize files, add rebar3 build, GH actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Sep 1, 2021
1 parent 1f6b37f commit be7cee3
Show file tree
Hide file tree
Showing 22 changed files with 201 additions and 36 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/hex-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Hex Publish

on:
push:
tags:
- '*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v2

- name: Publish to Hex.pm
uses: erlangpack/github-action@v1
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
56 changes: 28 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# This workflow checks the tests and dialyzer.

name: Test

on: [push, pull_request]
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test-ubuntu:
runs-on: ubuntu-18.04
name: OTP ${{matrix.otp_version}}
linux:
name: Test on OTP ${{ matrix.otp_version }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
otp_version:
- 21.3
- 22.3
- 23.2
steps:
- uses: actions/checkout@v2
- uses: gleam-lang/[email protected]
with:
otp-version: ${{matrix.otp_version}}
- run: |
erl -make
escript test.escript
otp_version: [22.3, 23.3, 24.0.5]
os: [ubuntu-latest]

container:
image: erlang:${{ matrix.otp_version }}

test-windows:
runs-on: windows-latest
name: Windows
steps:
- uses: actions/checkout@v2
- uses: gleam-lang/[email protected]
with:
otp-version: 23.2
id: setup
- run: |
$env:PATH = "${{ steps.setup.outputs.erlpath }}\bin;$env:PATH"
erl.exe -make
escript.exe test.escript
- uses: actions/checkout@v2
- name: Compile
run: make
- name: Test
run: make test
- name: XRef
run: make xref
- name: Dialyzer
run: make dialyzer
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 2.1.0

* Automatic test builds

* rebar3 build tool

* reorganize tests to use CT and rebar3


# 2.0.0

* **Erlang/OTP 21 or greater now required**
Expand Down
1 change: 0 additions & 1 deletion Emakefile

This file was deleted.

31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
REBAR := ./rebar3
REBAR_URL := https://s3.amazonaws.com/rebar3/rebar3
ERL ?= erl

.PHONY: all compile shell test clean xref dialyzer

all: compile

compile: $(REBAR)
$(REBAR) compile

shell: $(REBAR)
$(REBAR) shell

test: $(REBAR)
$(REBAR) as test ct

clean: $(REBAR)
$(REBAR) clean

xref: $(REBAR)
$(REBAR) as test xref

dialyzer: $(REBAR)
$(REBAR) as test dialyzer

./rebar3:
$(ERL) -noshell -s inets -s ssl \
-eval '{ok, saved_to_file} = httpc:request(get, {"$(REBAR_URL)", []}, [], [{stream, "./rebar3"}])' \
-s init stop
chmod +x ./rebar3
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ An Erlang implementation of [The OAuth 1.0 Protocol](https://tools.ietf.org/html
Functions for generating signatures (client side), verifying signatures (server side),
and some convenience functions for making OAuth HTTP requests (client side).

## Usage

Erlang-ouath is on Hex, you can use the package by:

{deps, [
{oauth, "2.1.0"}
]}.


## Erlang/OTP compatibility

Expand Down
7 changes: 0 additions & 7 deletions ebin/oauth.app

This file was deleted.

9 changes: 9 additions & 0 deletions src/oauth.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{application, oauth, [
{description, "An Erlang OAuth 1.0 implementation"},
{vsn, git},
{modules, [oauth]},
{registered, []},
{applications, [kernel, stdlib, crypto, public_key, inets]},
{licenses, ["MIT License"]},
{links, [{"GitHub", "https://github.com/erlangpack/erlang-oauth"}]}
]}.
98 changes: 98 additions & 0 deletions test/oauth_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
%% -*- coding: utf-8 -*-
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2021 Marc Worrell
%%
%% -------------------------------------------------------------------

-module(oauth_SUITE).
-compile(export_all).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

%% ------------------------------------------------------------
%% Tests list
%% ------------------------------------------------------------

all() ->
[
signature_base_string,
plaintext,
hmac_sha1,
rsa_sha1
].

%% ------------------------------------------------------------
%% Init & clean
%% ------------------------------------------------------------

init_per_suite(Config) ->
Config.

end_per_suite(_Config) ->
ok.

init_per_testcase(_TestCase, Config) ->
Config.

end_per_testcase(_TestCase, _Config) ->
ok.

%% ------------------------------------------------------------
%% Test cases
%% ------------------------------------------------------------


signature_base_string(Config) ->
test_with(
Config,
"base_string_test_*",
[method, url, params, base_string],
fun (Method, URL, Params, BaseString) ->
[?_assertEqual(BaseString, oauth:signature_base_string(Method, URL, Params))]
end).

plaintext(Config) ->
test_with(
Config,
"plaintext_test_*",
[consumer, token_secret, signature],
fun (Consumer, TokenSecret, Signature) ->
SignatureTest = ?_assertEqual(Signature, oauth:plaintext_signature(Consumer, TokenSecret)),
VerifyTest = ?_assertEqual(true, oauth:plaintext_verify(Signature, Consumer, TokenSecret)),
[SignatureTest, VerifyTest]
end).

hmac_sha1(Config) ->
test_with(
Config,
"hmac_sha1_test_*",
[base_string, consumer, token_secret, signature],
fun (BaseString, Consumer, TokenSecret, Signature) ->
SignatureTest = ?_assertEqual(Signature, oauth:hmac_sha1_signature(BaseString, Consumer, TokenSecret)),
VerifyTest = ?_assertEqual(true, oauth:hmac_sha1_verify(Signature, BaseString, Consumer, TokenSecret)),
[SignatureTest, VerifyTest]
end).

rsa_sha1(Config) ->
Pkey = data_path(Config, "rsa_sha1_private_key.pem"),
Cert = data_path(Config, "rsa_sha1_certificate.pem"),
[BaseString, Signature] = read([base_string, signature], data_path(Config, "rsa_sha1_test")),
SignatureTest = ?_assertEqual(Signature, oauth:rsa_sha1_signature(BaseString, {"", Pkey, rsa_sha1})),
VerifyTest = ?_assertEqual(true, oauth:rsa_sha1_verify(Signature, BaseString, {"", Cert, rsa_sha1})),
[SignatureTest, VerifyTest].

test_with(Config, FilenamePattern, Keys, Fun) ->
lists:flatten(
lists:map(
fun (Path) -> apply(Fun, read(Keys, Path)) end,
filelib:wildcard(data_path(Config, FilenamePattern)))).

data_path(Config, Basename) ->
DataDir = ?config(data_dir, Config),
filename:join([DataDir, Basename]).

read(Keys, Path) ->
{ok, Proplist} = file:consult(Path),
[ proplists:get_value(K, Proplist) || K <- Keys ].
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit be7cee3

Please sign in to comment.