diff options
author | tusooa <tusooa@kazv.moe> | 2023-03-04 19:50:47 -0500 |
---|---|---|
committer | tusooa <tusooa@kazv.moe> | 2023-05-02 16:32:10 -0400 |
commit | 85bdbb102e8fe4dc4a0eb765d8a2a01308161772 (patch) | |
tree | 25c688a0fde6b14f437369e3f7eded6be8ae558f /test | |
parent | d97425d49e9bbc62c01e3bc6874b8d1067e46fd6 (diff) | |
download | pleroma-85bdbb102e8fe4dc4a0eb765d8a2a01308161772.tar.gz pleroma-85bdbb102e8fe4dc4a0eb765d8a2a01308161772.zip |
Add extraction process for oauth scopes
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/web/api_spec/scopes/compiler_test.exs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/pleroma/web/api_spec/scopes/compiler_test.exs b/test/pleroma/web/api_spec/scopes/compiler_test.exs new file mode 100644 index 000000000..99e1d343a --- /dev/null +++ b/test/pleroma/web/api_spec/scopes/compiler_test.exs @@ -0,0 +1,56 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ApiSpec.Scopes.CompilerTest do + use ExUnit.Case, async: true + + alias Pleroma.Web.ApiSpec.Scopes.Compiler + + @dummy_response %{} + + @data %{ + paths: %{ + "/mew" => %OpenApiSpex.PathItem{ + post: %OpenApiSpex.Operation{ + security: [%{"oAuth" => ["a:b:c"]}], + responses: @dummy_response + }, + get: %OpenApiSpex.Operation{security: nil, responses: @dummy_response} + }, + "/mew2" => %OpenApiSpex.PathItem{ + post: %OpenApiSpex.Operation{ + security: [%{"oAuth" => ["d:e", "f:g"]}], + responses: @dummy_response + }, + get: %OpenApiSpex.Operation{security: nil, responses: @dummy_response} + } + } + } + + describe "process_scope/1" do + test "gives all higher-level scopes" do + scopes = Compiler.process_scope("admin:read:accounts") + + assert [_, _, _] = scopes + assert "admin" in scopes + assert "admin:read" in scopes + assert "admin:read:accounts" in scopes + end + end + + describe "extract_all_scopes_from/1" do + test "extracts scopes" do + scopes = Compiler.extract_all_scopes_from(@data) + + assert [_, _, _, _, _, _, _] = scopes + assert "a" in scopes + assert "a:b" in scopes + assert "a:b:c" in scopes + assert "d" in scopes + assert "d:e" in scopes + assert "f" in scopes + assert "f:g" in scopes + end + end +end |