mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 18:51:10 +01:00
redesign bearer tokens
This commit is contained in:
@@ -107,7 +107,7 @@ public class BearerRealmTest
|
||||
|
||||
String compact = createCompactToken(marvin.getName(), key);
|
||||
|
||||
BearerAuthenticationToken token = new BearerAuthenticationToken(compact);
|
||||
BearerToken token = BearerToken.valueOf(compact);
|
||||
AuthenticationInfo info = realm.doGetAuthenticationInfo(token);
|
||||
|
||||
assertNotNull(info);
|
||||
@@ -142,7 +142,7 @@ public class BearerRealmTest
|
||||
Scope.valueOf("repo:*", "user:*")
|
||||
);
|
||||
|
||||
AuthenticationInfo info = realm.doGetAuthenticationInfo(new BearerAuthenticationToken(compact));
|
||||
AuthenticationInfo info = realm.doGetAuthenticationInfo(BearerToken.valueOf(compact));
|
||||
Scope scope = info.getPrincipals().oneByType(Scope.class);
|
||||
assertThat(scope, Matchers.containsInAnyOrder("repo:*", "user:*"));
|
||||
}
|
||||
@@ -170,7 +170,7 @@ public class BearerRealmTest
|
||||
expectedException.expectMessage(Matchers.containsString("claims"));
|
||||
|
||||
// kick authentication
|
||||
realm.doGetAuthenticationInfo(new BearerAuthenticationToken(compact));
|
||||
realm.doGetAuthenticationInfo(BearerToken.valueOf(compact));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +191,7 @@ public class BearerRealmTest
|
||||
Date exp = new Date(System.currentTimeMillis() - 600l);
|
||||
String compact = createCompactToken(trillian.getName(), key, exp, Scope.empty());
|
||||
|
||||
realm.doGetAuthenticationInfo(new BearerAuthenticationToken(compact));
|
||||
realm.doGetAuthenticationInfo(BearerToken.valueOf(compact));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,7 +206,7 @@ public class BearerRealmTest
|
||||
User trillian = UserTestData.createTrillian();
|
||||
String compact = createCompactToken(trillian.getName(), createSecureKey());
|
||||
|
||||
realm.doGetAuthenticationInfo(new BearerAuthenticationToken(compact));
|
||||
realm.doGetAuthenticationInfo(BearerToken.valueOf(compact));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +222,7 @@ public class BearerRealmTest
|
||||
|
||||
String compact = Jwts.builder().setSubject("test").compact();
|
||||
|
||||
realm.doGetAuthenticationInfo(new BearerAuthenticationToken(compact));
|
||||
realm.doGetAuthenticationInfo(BearerToken.valueOf(compact));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import sonia.scm.security.BearerAuthenticationToken;
|
||||
import sonia.scm.security.BearerToken;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,8 +71,8 @@ public class BearerWebTokenGeneratorTest {
|
||||
when(request.getHeader("Authorization")).thenReturn("Bearer asd");
|
||||
AuthenticationToken token = tokenGenerator.createToken(request);
|
||||
assertNotNull(token);
|
||||
assertThat(token, instanceOf(BearerAuthenticationToken.class));
|
||||
BearerAuthenticationToken bt = (BearerAuthenticationToken) token;
|
||||
assertThat(token, instanceOf(BearerToken.class));
|
||||
BearerToken bt = (BearerToken) token;
|
||||
assertThat(bt.getCredentials(), equalTo("asd"));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import sonia.scm.security.BearerAuthenticationToken;
|
||||
import sonia.scm.security.BearerToken;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -74,7 +74,7 @@ public class CookieBearerWebTokenGeneratorTest
|
||||
when(c.getValue()).thenReturn("value");
|
||||
when(request.getCookies()).thenReturn(new Cookie[] { c });
|
||||
|
||||
BearerAuthenticationToken token = tokenGenerator.createToken(request);
|
||||
BearerToken token = tokenGenerator.createToken(request);
|
||||
|
||||
assertNotNull(token);
|
||||
assertEquals("value", token.getCredentials());
|
||||
|
||||
Reference in New Issue
Block a user