Skip to content

Commit

Permalink
Fix several escaped http URLs to https.
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Walls committed Apr 4, 2019
1 parent d1234a7 commit ae2234d
Show file tree
Hide file tree
Showing 36 changed files with 405 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import org.springframework.social.facebook.api.impl.FacebookTemplate;

public class AchievementOperationsITests extends FacebookITest {

private TestUser testUser1;
private AchievementOperations achievementOps;

public AchievementOperationsITests() {
// Had to create a separate app to test achievements with, because achievements only work for game apps.
super("248041811986157", "783e6b8d5239b22881c8cd925d91e623");
Expand All @@ -43,13 +43,13 @@ public void setupTestUsers() {
FacebookTemplate facebook1 = new FacebookTemplate(testUser1.getAccessToken());
achievementOps = facebook1.achievementOperations();
}


@Test
public void achievementTests() {
// TODO: Might want to host these somewhere other than my (Craig's) personal hosting provider
clientFacebook.achievementOperations().createAchievementType("http://www.habuma.com/fb/foundwaldo.html", 1);
clientFacebook.achievementOperations().createAchievementType("http://www.habuma.com/fb/tiedshoes.html", 2);
clientFacebook.achievementOperations().createAchievementType("https://www.habuma.com/fb/foundwaldo.html", 1);
clientFacebook.achievementOperations().createAchievementType("https://www.habuma.com/fb/tiedshoes.html", 2);

List<AchievementType> achievementTypes = clientFacebook.achievementOperations().getAchievementTypes();
assertEquals(2, achievementTypes.size());
Expand All @@ -61,13 +61,13 @@ public void achievementTests() {
assertEquals(achievementType.getTitle(), fetched.getTitle());
assertEquals(achievementType.getType(), fetched.getType());
}


List<Achievement> achievements = achievementOps.getAchievements();
assertEquals(0, achievements.size());
String achieveId = achievementOps.postAchievement("http://www.habuma.com/fb/foundwaldo.html");
String achieveId2 = achievementOps.postAchievement("http://www.habuma.com/fb/tiedshoes.html");
String achieveId = achievementOps.postAchievement("https://www.habuma.com/fb/foundwaldo.html");
String achieveId2 = achievementOps.postAchievement("https://www.habuma.com/fb/tiedshoes.html");

achievements = achievementOps.getAchievements();
assertEquals(2, achievements.size());
Achievement achievement = achievements.get(0);
Expand All @@ -88,7 +88,7 @@ public void achievementTests() {
assertEquals(testUser1.getId(), achievement.getFrom().getId());
assertEquals("Alice Arensen", achievement.getFrom().getName());


achievement = achievementOps.getAchievement(achieveId);
assertEquals(achieveId, achievement.getId());
assertEquals("games.achieves", achievement.getType());
Expand All @@ -97,16 +97,16 @@ public void achievementTests() {
assertEquals("Spring Social Game", achievement.getApplication().getName());
assertEquals(testUser1.getId(), achievement.getFrom().getId());
assertEquals("Alice Arensen", achievement.getFrom().getName());
achievementOps.removeAchievement("http://www.habuma.com/fb/foundwaldo.html");
achievementOps.removeAchievement("http://www.habuma.com/fb/tiedshoes.html");

achievementOps.removeAchievement("https://www.habuma.com/fb/foundwaldo.html");
achievementOps.removeAchievement("https://www.habuma.com/fb/tiedshoes.html");
achievements = achievementOps.getAchievements();
assertEquals(0, achievements.size());

clientFacebook.achievementOperations().removeAchievementType(achievementTypes.get(0).getUrl());
clientFacebook.achievementOperations().removeAchievementType(achievementTypes.get(1).getUrl());
achievementTypes = clientFacebook.achievementOperations().getAchievementTypes();
assertEquals(0, achievementTypes.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
public class FeedOperationsITests extends FacebookITest implements ITestCredentials {

private static final Logger logger = Logger.getLogger(FeedOperationsITests.class.getName());

private TestUser testUser1;
private TestUser testUser2;
private FeedOperations feedOps1;
private FeedOperations feedOps2;
private FacebookTemplate facebook1;
private FacebookTemplate facebook2;

public FeedOperationsITests() {
super(APP_ID, APP_SECRET);
}
Expand All @@ -53,13 +53,13 @@ public void setupTestUsers() {
facebook2 = new FacebookTemplate(testUser2.getAccessToken());
facebook1.testUserOperations().sendConfirmFriends(testUser1, testUser2);
facebook2.testUserOperations().sendConfirmFriends(testUser2, testUser1);

feedOps1 = facebook1.feedOperations();
feedOps2 = facebook2.feedOperations();

logger.info("CREATED TEST USERS: " + testUser1.getId() + " , " + testUser2.getId());
}


@Test
public void statusTests() {
Expand All @@ -68,7 +68,7 @@ public void statusTests() {
String fullPostId = feedOps1.updateStatus("Hello");
String postId = extractPostId(fullPostId);
logger.info("CREATED POST: " + fullPostId + " (" + postId + ")");

statuses = feedOps1.getStatuses();
assertEquals(1, statuses.size());
Post post = statuses.get(0);
Expand All @@ -91,30 +91,30 @@ public void feedTests() throws Exception {
String statusId = feedOps1.updateStatus("Hello");
feed = feedOps1.getFeed();
assertEquals(2, feed.size());
String linkId = feedOps1.postLink("Here's a link", new FacebookLink("http://test.org", "NAME", "CAPTION", "DESCRIPTION"));

String linkId = feedOps1.postLink("Here's a link", new FacebookLink("https://test.org", "NAME", "CAPTION", "DESCRIPTION"));
feed = feedOps1.getFeed();
assertEquals(3, feed.size());

PagedList<Post> links = feedOps1.getLinks();
assertEquals(1, links.size());
assertEquals(extractPostId(linkId), links.get(0).getId());

PagedList<Post> statuses = feedOps1.getStatuses();
assertEquals(2, statuses.size());
statusId = extractPostId(statusId);
// the status is never consistently the first or second, so just assert that it is one of the two statuses.
assertTrue(statusId.equals(statuses.get(0).getId()) || statusId.equals(statuses.get(1).getId()));

PagedList<Post> posts = feedOps1.getPosts();
assertEquals(3, posts.size());

PagedList<Post> homeFeed = feedOps1.getHomeFeed();
assertEquals(2, homeFeed.size());
assertEquals("Here's a link", homeFeed.get(0).getMessage());
assertEquals("Hello", homeFeed.get(1).getMessage());
}

@Test
public void tagTests() throws Exception {
// tag a user in a post
Expand All @@ -132,7 +132,7 @@ public void tagTests() throws Exception {
// assertEquals("Hiya!", tagged.get(0).getMessage());
// assertEquals(testUser2.getId(), tagged.get(0).getFrom().getId());
}

@Test
public void checkinTests() throws Exception {
PagedList<Post> checkins = feedOps1.getCheckins();
Expand All @@ -144,7 +144,7 @@ public void checkinTests() throws Exception {
assertEquals("Yo!", checkins.get(0).getMessage());
assertEquals("111625055543961", checkins.get(0).getPlace().getId());
}

private String extractPostId(String fullPostId) {
// The full post ID is the post ID prefixed by "{user-id}_"...strip off the prefix.
return fullPostId.substring(testUser1.getId().length() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public void getAchievement() throws Exception {
mockServer.expect(requestTo(fbUrl("1403783649909361")))
.andExpect(method(GET))
.andRespond(withSuccess(jsonResource("achievement"), MediaType.APPLICATION_JSON));

Achievement achievement = facebook.achievementOperations().getAchievement("1403783649909361");
assertFoundWaldoAchievement(achievement);
}

@Test
public void getAchievements() throws Exception {
mockServer.expect(requestTo(fbUrl("me/achievements")))
.andExpect(method(GET))
.andRespond(withSuccess(jsonResource("achievements"), MediaType.APPLICATION_JSON));

List<Achievement> achievements = facebook.achievementOperations().getAchievements();
assertEquals(2, achievements.size());
assertFoundWaldoAchievement(achievements.get(0));
Expand All @@ -61,9 +61,9 @@ public void postAchievement() throws Exception {
mockServer.expect(requestTo(fbUrl("me/achievements")))
.andExpect(method(POST))
.andExpect(header("Authorization", "OAuth " + ACCESS_TOKEN))
.andExpect(content().string("achievement=http%3A%2F%2Fexample.com%2Fachievement"))
.andExpect(content().string("achievement=https%3A%2F%2Fexample.com%2Fachievement"))
.andRespond(withSuccess(jsonResource("id-only"), MediaType.APPLICATION_JSON));

String achievementId = facebook.achievementOperations().postAchievement("https://example.com/achievement");
assertEquals("297875170268724", achievementId);
mockServer.verify();
Expand All @@ -74,24 +74,24 @@ public void deleteAchievement() throws Exception {
mockServer.expect(requestTo(fbUrl("me/achievements")))
.andExpect(method(POST))
.andExpect(header("Authorization", "OAuth " + ACCESS_TOKEN))
.andExpect(content().string("achievement=http%3A%2F%2Fexample.com%2Fachievement&method=delete"))
.andExpect(content().string("achievement=https%3A%2F%2Fexample.com%2Fachievement&method=delete"))
.andRespond(withSuccess("true", MediaType.APPLICATION_JSON));
facebook.achievementOperations().removeAchievement("https://example.com/achievement");
mockServer.verify();
}


//
// Application-level achievement type operations
//

@Test
public void getAchievementTypes() throws Exception {
appFacebookMockServer.expect(requestTo(fbUrl("app/achievements")))
.andExpect(method(GET))
.andExpect(header("Authorization", "OAuth " + APP_ACCESS_TOKEN))
.andRespond(withSuccess(jsonResource("achievement-types"), MediaType.APPLICATION_JSON));

List<AchievementType> achievementTypes = appFacebook.achievementOperations().getAchievementTypes();
assertEquals(2, achievementTypes.size());
assertWaldoAchievement(achievementTypes.get(0), null);
Expand All @@ -104,19 +104,19 @@ public void getAchievementType() throws Exception {
.andExpect(method(GET))
.andExpect(header("Authorization", "OAuth " + APP_ACCESS_TOKEN))
.andRespond(withSuccess(jsonResource("achievement-type"), MediaType.APPLICATION_JSON));

AchievementType achievementType = appFacebook.achievementOperations().getAchievementType("651053301631017");
assertWaldoAchievement(achievementType, "2014-05-29T17:23:36+0000");
}

@Test
public void createAchievementType() throws Exception {
appFacebookMockServer.expect(requestTo(fbUrl("app/achievements")))
.andExpect(method(POST))
.andExpect(header("Authorization", "OAuth " + APP_ACCESS_TOKEN))
.andExpect(content().string("achievement=http%3A%2F%2Fexample.com%2Fachievement&display_order=2"))
.andExpect(content().string("achievement=https%3A%2F%2Fexample.com%2Fachievement&display_order=2"))
.andRespond(withSuccess("true", MediaType.APPLICATION_JSON));

appFacebook.achievementOperations().createAchievementType("https://example.com/achievement", 2);
appFacebookMockServer.verify();
}
Expand All @@ -126,16 +126,16 @@ public void removeAchievementType() throws Exception {
appFacebookMockServer.expect(requestTo(fbUrl("app/achievements")))
.andExpect(method(POST))
.andExpect(header("Authorization", "OAuth " + APP_ACCESS_TOKEN))
.andExpect(content().string("achievement=http%3A%2F%2Fexample.com%2Fachievement&method=delete"))
.andExpect(content().string("achievement=https%3A%2F%2Fexample.com%2Fachievement&method=delete"))
.andRespond(withSuccess("true", MediaType.APPLICATION_JSON));
appFacebook.achievementOperations().removeAchievementType("https://example.com/achievement");
appFacebookMockServer.verify();
}



// private helpers

private void assertFoundWaldoAchievement(Achievement achievement) {
assertEquals("1403833783237681", achievement.getId());
assertEquals("248041811986157", achievement.getApplication().getId());
Expand All @@ -144,7 +144,7 @@ private void assertFoundWaldoAchievement(Achievement achievement) {
assertEquals("651053301631017", achievement.getAchievementType().getId());
assertEquals("Found Waldo", achievement.getAchievementType().getTitle());
assertEquals("game.achievement", achievement.getAchievementType().getType());
assertEquals("http://www.habuma.com/fb/foundwaldo.html", achievement.getAchievementType().getUrl());
assertEquals("https://www.habuma.com/fb/foundwaldo.html", achievement.getAchievementType().getUrl());
assertEquals(0, achievement.getImportance());
assertEquals("1401275846826808", achievement.getFrom().getId());
assertEquals("Carol Amhccbahibha Zuckersky", achievement.getFrom().getName());
Expand All @@ -160,14 +160,14 @@ private void assertTiedShoesAchievement(Achievement achievement) {
assertEquals("891536160872086", achievement.getAchievementType().getId());
assertEquals("Tied shoes", achievement.getAchievementType().getTitle());
assertEquals("game.achievement", achievement.getAchievementType().getType());
assertEquals("http://www.habuma.com/fb/tiedshoes.html", achievement.getAchievementType().getUrl());
assertEquals("https://www.habuma.com/fb/tiedshoes.html", achievement.getAchievementType().getUrl());
assertEquals(1, achievement.getImportance());
assertEquals("1401275846826808", achievement.getFrom().getId());
assertEquals("Carol Amhccbahibha Zuckersky", achievement.getFrom().getName());
assertEquals(toDate("2014-06-02T14:35:45+0000"), achievement.getPublishTime());
assertEquals("games.achieves", achievement.getType());
}

private void assertWaldoAchievement(AchievementType achievementType, String createdTime) {
assertEquals("248041811986157", achievementType.getApplication().getId());
assertEquals("Spring Social Game", achievementType.getApplication().getName());
Expand All @@ -179,30 +179,30 @@ private void assertWaldoAchievement(AchievementType achievementType, String crea
}
assertEquals("He's sneaky in red and white stripes and hiding in crowds, but you found him!", achievementType.getDescription());
assertEquals("651053301631017", achievementType.getId());
assertEquals("http://www.habuma.com/fb/foundwaldo.jpg", achievementType.getImage().getUrl());
assertEquals("https://www.habuma.com/fb/foundwaldo.jpg", achievementType.getImage().getUrl());
assertEquals(1517, achievementType.getImage().getHeight());
assertEquals(827, achievementType.getImage().getWidth());
assertEquals(50, achievementType.getPoints());
assertEquals("Found Waldo", achievementType.getTitle());
assertEquals("game.achievement", achievementType.getType());
assertEquals(toDate("2014-05-29T17:23:36+0000"), achievementType.getUpdatedTime());
assertEquals("http://www.habuma.com/fb/foundwaldo.html", achievementType.getUrl());
assertEquals("https://www.habuma.com/fb/foundwaldo.html", achievementType.getUrl());
}

private void assertTiedShoesAchievement(AchievementType achievementType) {
assertEquals("248041811986157", achievementType.getApplication().getId());
assertEquals("Spring Social Game", achievementType.getApplication().getName());
assertEquals("https://www.facebook.com/apps/application.php?id=248041811986157", achievementType.getApplication().getUrl());
assertNull(achievementType.getCreatedTime());
assertEquals("You're not losing your sneakers. Not again!", achievementType.getDescription());
assertEquals("891536160872086", achievementType.getId());
assertEquals("http://www.habuma.com/fb/tiedshoes.jpg", achievementType.getImage().getUrl());
assertEquals("https://www.habuma.com/fb/tiedshoes.jpg", achievementType.getImage().getUrl());
assertEquals(1517, achievementType.getImage().getHeight());
assertEquals(827, achievementType.getImage().getWidth());
assertEquals(10, achievementType.getPoints());
assertEquals("Tied shoes", achievementType.getTitle());
assertEquals("game.achievement", achievementType.getType());
assertEquals(toDate("2014-05-29T17:30:47+0000"), achievementType.getUpdatedTime());
assertEquals("http://www.habuma.com/fb/tiedshoes.html", achievementType.getUrl());
assertEquals("https://www.habuma.com/fb/tiedshoes.html", achievementType.getUrl());
}
}
Loading

0 comments on commit ae2234d

Please sign in to comment.