A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.1 KiB

  1. package writefreely
  2. import (
  3. "context"
  4. "database/sql"
  5. "github.com/stretchr/testify/assert"
  6. "testing"
  7. )
  8. func TestOAuthDatastore(t *testing.T) {
  9. if !runMySQLTests() {
  10. t.Skip("skipping mysql tests")
  11. }
  12. withTestDB(t, func(db *sql.DB) {
  13. ctx := context.Background()
  14. ds := &datastore{
  15. DB: db,
  16. driverName: "",
  17. }
  18. state, err := ds.GenerateOAuthState(ctx)
  19. assert.NoError(t, err)
  20. assert.Len(t, state, 24)
  21. countRows(t, ctx, db, 1, "SELECT COUNT(*) FROM `oauth_client_state` WHERE `state` = ? AND `used` = false", state)
  22. err = ds.ValidateOAuthState(ctx, state)
  23. assert.NoError(t, err)
  24. countRows(t, ctx, db, 1, "SELECT COUNT(*) FROM `oauth_client_state` WHERE `state` = ? AND `used` = true", state)
  25. var localUserID int64 = 99
  26. var remoteUserID int64 = 100
  27. err = ds.RecordRemoteUserID(ctx, localUserID, remoteUserID)
  28. assert.NoError(t, err)
  29. countRows(t, ctx, db, 1, "SELECT COUNT(*) FROM `users_oauth` WHERE `user_id` = ? AND `remote_user_id` = ?", localUserID, remoteUserID)
  30. foundUserID, err := ds.GetIDForRemoteUser(ctx, remoteUserID)
  31. assert.NoError(t, err)
  32. assert.Equal(t, localUserID, foundUserID)
  33. })
  34. }