@@ -107,6 +107,7 @@ defmodule Hex.RepoTest do
107107 assert { :ok ,
108108 % {
109109 auth_key: nil ,
110+ oauth_exchange: true ,
110111 public_key: _ ,
111112 trusted: true ,
112113 url: "http://localhost:4043/repo/repos/acme"
@@ -126,6 +127,7 @@ defmodule Hex.RepoTest do
126127 assert { :ok ,
127128 % {
128129 auth_key: "key" ,
130+ oauth_exchange: true ,
129131 public_key: _ ,
130132 trusted: true ,
131133 url: "http://example.com/repos/acme"
@@ -145,6 +147,7 @@ defmodule Hex.RepoTest do
145147 assert { :ok ,
146148 % {
147149 auth_key: "key" ,
150+ oauth_exchange: true ,
148151 public_key: _ ,
149152 trusted: false ,
150153 url: "http://example.com/repos/acme"
@@ -160,6 +163,7 @@ defmodule Hex.RepoTest do
160163 url: "http://example.com" ,
161164 public_key: "public" ,
162165 auth_key: "auth" ,
166+ oauth_exchange: true ,
163167 trusted: true
164168 } ,
165169 "hexpm:acme" => % { }
@@ -168,6 +172,7 @@ defmodule Hex.RepoTest do
168172 assert % {
169173 "hexpm:acme" => % {
170174 auth_key: "auth" ,
175+ oauth_exchange: true ,
171176 public_key: "public" ,
172177 trusted: true ,
173178 url: "http://example.com/repos/acme"
@@ -188,6 +193,47 @@ defmodule Hex.RepoTest do
188193 end
189194
190195 describe "automatic API key to OAuth token exchange" do
196+ test "organization repo inherits oauth_exchange from parent" do
197+ auth =
198+ HexTest.Hexpm . new_user (
199+ "org_oauth_user" ,
200+ "org_oauth@example.com" ,
201+ "password" ,
202+ "org_oauth_key"
203+ )
204+
205+ repos = Hex.State . fetch! ( :repos )
206+ repos = put_in ( repos [ "hexpm" ] . auth_key , auth [ :key ] )
207+ Hex.State . put ( :repos , repos )
208+
209+ assert { :ok , { 200 , _ , _ } } = Hex.Repo . get_package ( "hexpm:testorg" , "foo" , "" )
210+
211+ repos_after = Hex.State . fetch! ( :repos )
212+ token_data = repos_after [ "hexpm:testorg" ] . oauth_token
213+ assert is_binary ( token_data [ "access_token" ] )
214+ end
215+
216+ test "organization repo skips oauth_exchange when disabled on parent" do
217+ auth =
218+ HexTest.Hexpm . new_user (
219+ "org_no_oauth_user" ,
220+ "org_no_oauth@example.com" ,
221+ "password" ,
222+ "org_no_oauth_key"
223+ )
224+
225+ repos = Hex.State . fetch! ( :repos )
226+ repos = put_in ( repos [ "hexpm" ] . auth_key , auth [ :key ] )
227+ repos = put_in ( repos [ "hexpm" ] , Map . put ( repos [ "hexpm" ] , :oauth_exchange , false ) )
228+ Hex.State . put ( :repos , repos )
229+
230+ assert { :ok , { 200 , _ , _ } } = Hex.Repo . get_package ( "hexpm:testorg" , "foo" , "" )
231+
232+ repos_after = Hex.State . fetch! ( :repos )
233+ org_repo = Map . get ( repos_after , "hexpm:testorg" )
234+ assert org_repo == nil or Map . get ( org_repo , :oauth_token ) == nil
235+ end
236+
191237 test "automatically exchanges API key for OAuth token when making request" do
192238 auth =
193239 HexTest.Hexpm . new_user (
0 commit comments