Browse Source

Reorganize files, add rebar3 build, GH actions.

Marc Worrell 3 years ago
parent
commit
be7cee3e78

+ 18 - 0
.github/workflows/hex-publish.yml

@@ -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 }}

+ 28 - 28
.github/workflows/test.yml

@@ -1,36 +1,36 @@
+# This workflow checks the tests and dialyzer.
+
 name: Test
 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:
 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:
     strategy:
       matrix:
       matrix:
-        otp_version:
-          - 21.3
-          - 22.3
-          - 23.2
-    steps:
-    - uses: actions/checkout@v2
-    - uses: gleam-lang/setup-erlang@v1.1.2
-      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:
     steps:
-    - uses: actions/checkout@v2
-    - uses: gleam-lang/setup-erlang@v1.1.2
-      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 - 0
CHANGELOG.md

@@ -1,3 +1,12 @@
+# 2.1.0
+
+ * Automatic test builds
+
+ * rebar3 build tool
+
+ * reorganize tests to use CT and rebar3
+
+
 # 2.0.0
 # 2.0.0
 
 
   * **Erlang/OTP 21 or greater now required**
   * **Erlang/OTP 21 or greater now required**

+ 0 - 1
Emakefile

@@ -1 +0,0 @@
-{"src/*", [debug_info, warn_unused_vars, warn_unused_import, {outdir, "ebin"}]}.

+ 31 - 0
Makefile

@@ -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 - 0
README.md

@@ -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),
 Functions for generating signatures (client side), verifying signatures (server side),
 and some convenience functions for making OAuth HTTP requests (client 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
 ## Erlang/OTP compatibility
 
 

+ 0 - 7
ebin/oauth.app

@@ -1,7 +0,0 @@
-{application, oauth, [
-  {description, "An Erlang OAuth 1.0 implementation"},
-  {vsn, "2.0.0"},
-  {modules, [oauth]},
-  {registered, []},
-  {applications, [kernel, stdlib, crypto, public_key, inets]}
-]}.

+ 9 - 0
src/oauth.app.src

@@ -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 - 0
test/oauth_SUITE.erl

@@ -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 ].

+ 0 - 0
testdata/base_string_test_A → test/oauth_SUITE_data/base_string_test_A


+ 0 - 0
testdata/base_string_test_B → test/oauth_SUITE_data/base_string_test_B


+ 0 - 0
testdata/base_string_test_C → test/oauth_SUITE_data/base_string_test_C


+ 0 - 0
testdata/base_string_test_D → test/oauth_SUITE_data/base_string_test_D


+ 0 - 0
testdata/hmac_sha1_test_A → test/oauth_SUITE_data/hmac_sha1_test_A


+ 0 - 0
testdata/hmac_sha1_test_B → test/oauth_SUITE_data/hmac_sha1_test_B


+ 0 - 0
testdata/hmac_sha1_test_C → test/oauth_SUITE_data/hmac_sha1_test_C


+ 0 - 0
testdata/plaintext_test_A → test/oauth_SUITE_data/plaintext_test_A


+ 0 - 0
testdata/plaintext_test_B → test/oauth_SUITE_data/plaintext_test_B


+ 0 - 0
testdata/plaintext_test_C → test/oauth_SUITE_data/plaintext_test_C


+ 0 - 0
testdata/rsa_sha1_certificate.pem → test/oauth_SUITE_data/rsa_sha1_certificate.pem


+ 0 - 0
testdata/rsa_sha1_private_key.pem → test/oauth_SUITE_data/rsa_sha1_private_key.pem


+ 0 - 0
testdata/rsa_sha1_test → test/oauth_SUITE_data/rsa_sha1_test