Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github Actions for CI #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["formatter.exs", "mix.exs", "{config,lib,test,priv}/**/*.{ex,exs}"]
]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ueberauth/developers
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---

name: Continuous Integration

on:
pull_request:
types:
- opened
- reopened
- synchronize

jobs:
Test:
runs-on: ubuntu-latest

container:
image: elixir:1.11-alpine

steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Install (mix)
run: |
mix local.rebar --force
mix local.hex --force

- name: Install (deps)
run: mix deps.get

- name: Run Tests
run: mix test

Format:
runs-on: ubuntu-latest

container:
image: elixir:1.11-alpine

steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Install (mix)
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get

- name: Run Formatter
run: mix format --check-formatted

Credo:
runs-on: ubuntu-latest

container:
image: elixir:1.11-alpine

steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Install (os)
run: apk add --no-cache gcc g++ git make musl-dev tar zstd

- name: Install (mix)
run: |
mix local.rebar --force
mix local.hex --force

- name: Install (deps)
run: mix deps.get

- name: Run Credo
run: mix credo
1 change: 1 addition & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 2 additions & 1 deletion lib/ueberauth/strategy/twitter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Ueberauth.Strategy.Twitter do
Handles initial request for Twitter authentication.
"""
def handle_request!(conn) do
token = Twitter.OAuth.request_token!([], [redirect_uri: callback_url(conn)])
token = Twitter.OAuth.request_token!([], redirect_uri: callback_url(conn))

conn
|> put_session(:twitter_token, token)
Expand All @@ -26,6 +26,7 @@ defmodule Ueberauth.Strategy.Twitter do
"""
def handle_callback!(%Plug.Conn{params: %{"oauth_verifier" => oauth_verifier}} = conn) do
token = get_session(conn, :twitter_token)

case Twitter.OAuth.access_token(token, oauth_verifier) do
{:ok, access_token} -> fetch_user(conn, access_token)
{:error, error} -> set_errors!(conn, [error(error.code, error.reason)])
Expand Down
17 changes: 10 additions & 7 deletions lib/ueberauth/strategy/twitter/internal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ defmodule Ueberauth.Strategy.Twitter.OAuth.Internal do
"""

def get(url, extraparams, {consumer_key, consumer_secret, _}, token \\ "", token_secret \\ "") do
creds = OAuther.credentials(
consumer_key: consumer_key,
consumer_secret: consumer_secret,
token: token,
token_secret: token_secret
)
creds =
OAuther.credentials(
consumer_key: consumer_key,
consumer_secret: consumer_secret,
token: token,
token_secret: token_secret
)

{header, params} =
"get"
|> OAuther.sign(url, extraparams, creds)
|> OAuther.header
|> OAuther.header()

HTTPoison.get(url, [header, {"Accept", "application/json"}], params: params)
|> decode_body()
Expand Down Expand Up @@ -45,6 +47,7 @@ defmodule Ueberauth.Strategy.Twitter.OAuth.Internal do
|> Enum.map(&String.split(&1, "="))
|> Enum.map(&List.to_tuple/1)
|> Enum.into(%{})

# |> Enum.reduce(%{}, fn({name, val}, acc) -> Map.put_new(acc, name, val) end)
end

Expand Down
11 changes: 7 additions & 4 deletions lib/ueberauth/strategy/twitter/oauth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ defmodule Ueberauth.Strategy.Twitter.OAuth do

alias Ueberauth.Strategy.Twitter.OAuth.Internal

@defaults [access_token: "/oauth/access_token",
authorize_url: "/oauth/authorize",
request_token: "/oauth/request_token",
site: "https://api.twitter.com"]
@defaults [
access_token: "/oauth/access_token",
authorize_url: "/oauth/authorize",
request_token: "/oauth/request_token",
site: "https://api.twitter.com"
]

defmodule ApiError do
@moduledoc "Raised on OAuth API errors."
Expand Down Expand Up @@ -60,6 +62,7 @@ defmodule Ueberauth.Strategy.Twitter.OAuth do
end

def get(url, access_token), do: get(url, [], access_token)

def get(url, params, {token, token_secret}) do
client()
|> to_url(url)
Expand Down
52 changes: 28 additions & 24 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ defmodule UeberauthTwitter.Mixfile do
@url "https://github.com/ueberauth/ueberauth_twitter"

def project do
[app: :ueberauth_twitter,
version: @version,
name: "Ueberauth Twitter Strategy",
package: package(),
elixir: "~> 1.1",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
source_url: @url,
homepage_url: @url,
description: description(),
deps: deps(),
docs: docs()]
[
app: :ueberauth_twitter,
version: @version,
name: "Ueberauth Twitter Strategy",
package: package(),
elixir: "~> 1.1",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
source_url: @url,
homepage_url: @url,
description: description(),
deps: deps(),
docs: docs()
]
end

def application do
Expand All @@ -25,14 +27,14 @@ defmodule UeberauthTwitter.Mixfile do

defp deps do
[
{:httpoison, "~> 1.0"},
{:oauther, "~> 1.1"},
{:ueberauth, "~> 0.6"},

# dev/test dependencies
{:earmark, ">= 0.0.0", only: :dev},
{:ex_doc, "~> 0.18", only: :dev},
{:credo, "~> 0.8", only: [:dev, :test]}
{:httpoison, "~> 1.0"},
{:oauther, "~> 1.1"},
{:ueberauth, "~> 0.6"},

# dev/test dependencies
{:earmark, ">= 0.0.0", only: :dev},
{:ex_doc, "~> 0.18", only: :dev},
{:credo, "~> 0.8", only: [:dev, :test]}
]
end

Expand All @@ -49,9 +51,11 @@ defmodule UeberauthTwitter.Mixfile do
end

defp package do
[files: ["lib", "mix.exs", "README.md", "LICENSE"],
maintainers: ["Sean Callan"],
licenses: ["MIT"],
links: %{"GitHub": @url}]
[
files: ["lib", "mix.exs", "README.md", "LICENSE"],
maintainers: ["Sean Callan"],
licenses: ["MIT"],
links: %{GitHub: @url}
]
end
end
12 changes: 7 additions & 5 deletions test/strategy/twitter/oauth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@ defmodule Ueberauth.Strategy.Twitter.OAuthTest do
alias Ueberauth.Strategy.Twitter.OAuth

setup do
Application.put_env :ueberauth, OAuth,
Application.put_env(:ueberauth, OAuth,
consumer_key: "consumer_key",
consumer_secret: "consumer_secret"
)

:ok
end

test "access_token!/2: raises an appropriate error on auth failure" do
assert_raise RuntimeError, ~r/401/i, fn ->
OAuth.access_token! {"badtoken", "badsecret"}, "badverifier"
OAuth.access_token!({"badtoken", "badsecret"}, "badverifier")
end
end

test "access_token!/2 raises an appropriate error on network failure" do
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
OAuth.access_token! {"token", "secret"}, "verifier", site: "https://bogusapi.twitter.com"
OAuth.access_token!({"token", "secret"}, "verifier", site: "https://bogusapi.twitter.com")
end
end

test "request_token!/2: raises an appropriate error on auth failure" do
assert_raise RuntimeError, ~r/401/i, fn ->
OAuth.request_token! [], redirect_uri: "some/uri"
OAuth.request_token!([], redirect_uri: "some/uri")
end
end

test "request_token!/2: raises an appropriate error on network failure" do
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
OAuth.request_token! [], site: "https://bogusapi.twitter.com", redirect_uri: "some/uri"
OAuth.request_token!([], site: "https://bogusapi.twitter.com", redirect_uri: "some/uri")
end
end
end